I looked at the implementation of the
ArrayString deserialization from the
arrayvec crate (https://docs.rs/arrayvec/0.5.1/src/arrayvec/array_string.rs.html#532), and
ArrayStringVisitor there defines both
visit_bytes methods. They both do the same thing, the only difference is that
visit_bytes checks if the bytes are valid ut8 first.
The same is true for the
StringVisitor from the
serde crate which is used to deserialize
String: https://docs.serde.rs/src/serde/de/impls.rs.html#307 (it also implements
visit_byte_buf for owned data).
I also looked at the
chrono crate and its
DateTimeVisitor, on the other hand, implements only
visit_str: https:// docs.rs/chrono/0.4.11/src/chrono/datetime.rs.html#1853.
Won't the utf8 check be already performed when you call
deserialize_string so that it is enough to implement just
visit_string, and if the data is not valid ut8 the deserializer will fail with a type error?
If I want to implement a custom deserializer for a type that is serialized as a string (I need to do some validations in a similar way like
chrono so can't just derive), should I implement both
visit_bytes? If yes, then why
chrono doesn't do it? And if
visit_str is enough, then why
arrayvec also implement