how do I write custom types to a CSV writer? #319
-
What version of the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is probably a good example of the XY Problem. That is, it looks like the actual problem you're trying to solve is, "how do I conveniently convert my custom data types to CSV data." But here, you're asking about how to implement In your case, Otherwise, more generally, the answer to the question of "how do I convert my custom data types to CSV" is to use Serde via |
Beta Was this translation helpful? Give feedback.
This is probably a good example of the XY Problem. That is, it looks like the actual problem you're trying to solve is, "how do I conveniently convert my custom data types to CSV data." But here, you're asking about how to implement
AsRef
in a way that doesn't result in returning a reference. The answer to the latter question is that you can't.write_record
is only for types that are known to be cheaply convertible to&[u8]
via theAsRef
trait. If you don't have that, then you can't usewrite_record
.In your case,
TagValue
can almost implementAsRef<[u8]>
. If you really want to go that route, then I'd suggest convertingTagValue
into a new type that does the necessary conversions, and the…