pub trait Value: Sized {
type Primitive: Primitive + ?Sized;
// Required methods
fn from_primitive(
value: <Self::Primitive as ToOwned>::Owned,
) -> Result<Self, Box<dyn Error>>;
fn to_primitive<'a>(
&'a self,
) -> Result<Cow<'a, Self::Primitive>, Box<dyn Error>>;
}
Expand description
A value that can be stored in a table, but must be converted first
This trait allows for any arbitrary type to be encodable and decodable
from a UTF table, as long as it can be converted into one of the core
storeable types (implementors of trait Primitive
).
§Example
#[derive(Default)]
struct Buffer(String);
impl Value for Buffer {
type Primitive = str;
fn from_primitive(value: String) -> Result<Self, Box<dyn Error>> {
Ok(Buffer(value))
}
fn to_primitive<'a>(&'a self) -> Result<Cow<'a, str>, Box<dyn Error>> {
Ok(Cow::Borrowed(&self.0))
}
}
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.