I way to provide my own implementation.
Maybe I'm just dumb, but is there a way to do something like:
enum Compression {
Lz4,
Gzip(u8),
}
Compression::Gzip(9).to_string() # returns gzip-9
Compression::from_str("gzip-2") # returns Compression::Gzip(2)
In this particular case, you could do something like this SO Answer. This doesn't work if there's more than one variant with additional data though. You need to manually implement Display and From<&str>.
In general, this is probably outside the scope of what strum is for. I'm not sure what the obvious, generalizable way of serializing enums with additional data on the variants that preserves the data, and that makes me think it's not a great candidate for this plugin.
The failure crate as a way to solve this somewhat nicely
#[derive(failure)]
pub enum MyError {
#[fail(display = "This is an error with props: {}, {}", _0, _1)]
Error(String, usize)
}
See https://boats.gitlab.io/failure/custom-fail.html for the docs on this, so it would be great if strum could implement the following
pub enum Compression {
#[strum(serialize = "gzip-{}", _0)]
Gzip(u8),
Lz4,
}
Closing old issues