dbase-rs
dbase-rs copied to clipboard
Have NamedValue.name be a Cow to allow for owned Strings
This changes the type of NamedValue
's name
field to be a Cow<str>
instead of &str
.
The reason I need this change is because in the project we are using this crate in, we have an alternative DBF implementation that reads/writes files in-place.
For de-serializing records we want to support the same mechanism already provided by this crate (since we use this crate and our own, which doesn't implement everything, at the same time),.
But since field names are read and decoded just as the iterator that generates the NamedValue
s in our case, we need to store the owned value in NamedValue
.
I tried using a generic argument for NamedValue
to have this backwards compaible, but Rust complains about the lifetime not being bound if I set a default value for the type parameter (but not if I don't...?). This was my original idea, which would have been backwards compatible:
pub struct NamedValue<'a, T, S=&'a str> where S: AsRef<str> + 'a {
/// Reference to the field name the value belongs to
pub name: S,
/// The value
pub value: T,
}