Closed nyurik closed 1 month ago
I would prefer not to build support for this into Serializer. It would be extremely unusual for a write_fmt
method to consume ownership of $dst. Ordinarily they operate on &mut self
.
But you can use serializer.collect_str(&format_args!(...))
instead to accomplish behavior that is equivalent.
The
write!($dst, $args+)
macro wraps a call to$dst.write_fmt(format_args!($($arg)*))
- making it ergonomic to use formatted output on anything "writable" --write!(dst, "foo={foo}")
. It seems serde does not supportwrite!
because it does not havewrite_fmt
, even though it has almost identical collect_str. Even its documentation implies similar usage pattern.Would it be possible to add another
write_fmt
fn to the Serializer to make this usecase easier? In theory, ifcollect_str
was calledwrite_fmt
, it would have worked out of the box, so a default Trait impl to simply forward the call should be possible?