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
AsRefin a way that doesn't result in returning a reference. The answer to the latter question is that you can't.write_recordis only for types that are known to be cheaply convertible to&[u8]via theAsReftrait. If you don't have that, then you can't usewrite_record.In your case,
TagValuecan almost implementAsRef<[u8]>. If you really want to go that route, then I'd suggest convertingTagValueinto a new type that does the necessary conversions, and the…