-
-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Front-page example doesn't compile on Rust stable (1.2) #150
Comments
Oops sorry about that! I just pushed up a working example. I think this was just an older example I forgot to update. I'm currently writing up documentation for serde, I'm sorry it's been taking so long. I personally think it's fine to write visitors, they are just a little complicated and I haven't yet figured out a great way to simplify them while keeping their performance. Anyway, some serializers and deserializers serialize structs differently than maps, such as bincode, which serializes structs essentially as a tuple with no field names. The One thing that might help is to actually look at what
Then run: |
Erick, thanks for the quick response! The documentation isn't bad—aside from having up-to-date examples and more explanation for parameters and abbreviations. Regarding visitors, what I found most confusing is the overloaded use of the word “visit.” While it's intuitive to have visitor types such as In Go the idiom is to name interfaces with a noun ending in “-er.” E.g., a Rust has traits instead of interfaces, but I think the “-er” naming scheme works well in many cases, just the same. For Serde, this suggests that, say, the |
Thanks, that's interesting idea, I've filed #151 to track it. |
bigint: small to_str_radix optimization Before: ``` test fac_to_string ... bench: 1,630 ns/iter (+/- 34) test fib_to_string ... bench: 359 ns/iter (+/- 11) test to_str_radix_02 ... bench: 3,097 ns/iter (+/- 19) test to_str_radix_08 ... bench: 1,146 ns/iter (+/- 38) test to_str_radix_10 ... bench: 4,248 ns/iter (+/- 36) test to_str_radix_16 ... bench: 881 ns/iter (+/- 44) test to_str_radix_36 ... bench: 8,073 ns/iter (+/- 75) ``` After: ``` test fac_to_string ... bench: 1,492 ns/iter (+/- 20) test fib_to_string ... bench: 368 ns/iter (+/- 7) test to_str_radix_02 ... bench: 2,038 ns/iter (+/- 47) test to_str_radix_08 ... bench: 812 ns/iter (+/- 9) test to_str_radix_10 ... bench: 3,919 ns/iter (+/- 40) test to_str_radix_16 ... bench: 703 ns/iter (+/- 58) test to_str_radix_36 ... bench: 7,852 ns/iter (+/- 81) ```
I copied-and-pasted the front-page example for “Deserialization without Macros”—specifically the section on structs—and tried to compile it, but it fails to compile.
All but one of the compiler errors are due to the
PointField
type being referred to asField
. I fixed those errors, but there remains one compiler error, which is at line 92 in the list below.I looked through the Serde documentation and source code but was unable to figure out what the call to
visit_struct
is supposed to be. Perhaps this example has gotten lost in the Serde API changes?I understand that the Serde
Serialize
andDeserialize
macros are first-class and that applications shouldn't be rolling out custom visitors for serialization and deserialization. However, the macros don't support renaming fields (#140), handling elided fields during deserialization (#90, #44), nor eliding default values during serialization (#43), and I need these features. So until the macros catch up with my use case, I must fall back to custom visitors.Can someone explain what the call to
visit_struct
is supposed to be?And perhaps someone can explain what the
_fields
parameter inserde::de::Deserializer::visit_struct
is for?And maybe someone can explain what “elt” means, as in
serde::ser::Serializer::visit_struct_elt
?The text was updated successfully, but these errors were encountered: