let expected = concat!( "struct SerializeWith < 'a , T > where T : Serialize { ", "value : & 'a String , ", "phantom : :: std :: marker :: PhantomData < Cow < 'a , str > > , ", "} ", "impl < 'a , T > :: serde :: Serialize for SerializeWith < 'a , T > where T : Serialize { ", "fn serialize < S > (& self , s : & mut S) -> Result < () , S :: Error > ", "where S : :: serde :: Serializer ", "{ ", "SomeTrait :: serialize_with (self . value , s) ", "} ", "} ", "SerializeWith { ", "value : self . x , ", "phantom : :: std :: marker :: PhantomData :: < Cow < 'a , str > > , ", "}"
);
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_integer() { let ii8 = -1i8; let ii16 = -1i16; let ii32 = -1i32; let ii64 = -1i64; let ii128 = -1i128; let iisize = -1isize; let uu8 = 1u8; let uu16 = 1u16; let uu32 = 1u32; let uu64 = 1u64; let uu128 = 1u128; let uusize = 1usize;
let tokens = quote! { #e32 #e64
}; let expected = concat!("2.345f32 2.345f64");
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_char() { let zero = '\u{1}'; let pound = '#'; let quote = '"'; let apost = '\''; let newline = '\n'; let heart = '\u{2764}';
let tokens = quote! { #zero#pound#quote#apost#newline#heart
}; let expected = "'\\u{1}' '#' '\"' '\\'''\\n''\u{2764}'";
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_str() { let s = "\u{1} a 'b \" c"; let tokens = quote!(#s); let expected = "\"\\u{1} a 'b \\\" c\"";
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_string() { let s = "\u{1} a 'b \" c".to_string(); let tokens = quote!(#s); let expected = "\"\\u{1} a 'b \\\" c\"";
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_duplicate_name_repetition() { let foo = &["a", "b"];
let tokens = quote! { #(#foo: #foo),* #(#foo: #foo),*
};
let expected = r#""a" : "a" , "b" : "b""a" : "a" , "b" : "b""#;
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_duplicate_name_repetition_no_copy() { let foo = vec!["a".to_owned(), "b".to_owned()];
let tokens = quote! { #(#foo: #foo),*
};
let expected = r#""a" : "a" , "b" : "b""#;
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_btreeset_repetition() { letmut set = BTreeSet::new();
set.insert("a".to_owned());
set.insert("b".to_owned());
let tokens = quote! { #(#set: #set),*
};
let expected = r#""a" : "a" , "b" : "b""#;
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_variable_name_conflict() { // The implementation of `#(...),*` uses the variable `_i` but it should be // fine, if a little confusing when debugging. let _i = vec!['a', 'b']; let tokens = quote! { #(#_i),* }; let expected = "'a' , 'b'";
assert_eq!(expected, tokens.to_string());
}
#[test] fn test_nonrep_in_repetition() { let rep = vec!["a", "b"]; let nonrep = "c";
let tokens = quote! { #(#rep#rep : #nonrep#nonrep),*
};
#[test] fn test_append_tokens() { letmut a = quote!(a); let b = quote!(b);
a.append_all(b);
assert_eq!("a b", a.to_string());
}
#[test] fn test_format_ident() { let id0 = format_ident!("Aa"); let id1 = format_ident!("Hello{x}", x = id0); let id2 = format_ident!("Hello{x}", x = 5usize); let id3 = format_ident!("Hello{}_{x}", id0, x = 10usize); let id4 = format_ident!("Aa", span = Span::call_site()); let id5 = format_ident!("Hello{}", Cow::Borrowed("World"));
#[test] fn test_format_ident_strip_raw() { let id = format_ident!("r#struct"); let my_id = format_ident!("MyId{}", id); let raw_my_id = format_ident!("r#MyId{}", id);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.