pub trait FromKv: Sized {
// Required method
fn from_kv(value: &str, span: Span) -> Result<Self>;
}Expand description
Trait for types that can be parsed from a KEY=VALUE string.
This is the extension point for custom types. Implement this trait to
allow your type to be used in a #[derive(Kv)] struct.
The span parameter indicates where in the input the value is located,
for error reporting.
§Example
use pkgsrc_kv::{FromKv, KvError, Span};
struct MyId(u32);
impl FromKv for MyId {
fn from_kv(value: &str, span: Span) -> Result<Self, KvError> {
value.parse::<u32>()
.map(MyId)
.map_err(|e| KvError::Parse {
message: e.to_string(),
span,
})
}
}Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".