use super::ValueBytes;
impl From<bytes::Bytes> for ValueBytes {
fn from(val: bytes::Bytes) -> Self {
ValueBytes(Some(val))
}
}
impl<T> From<&T> for ValueBytes
where
T: Into<ValueBytes> + Clone,
{
fn from(val: &T) -> Self {
val.clone().into()
}
}
impl<T> From<Option<T>> for ValueBytes
where
T: Into<ValueBytes>,
{
fn from(val: Option<T>) -> Self {
match val {
Some(value) => value.into(),
None => ValueBytes(None),
}
}
}
impl TryFrom<ValueBytes> for Option<bytes::Bytes> {
type Error = crate::Error;
fn try_from(value: ValueBytes) -> Result<Self, Self::Error> {
Ok(value.0)
}
}
impl TryFrom<ValueBytes> for bytes::Bytes {
type Error = crate::Error;
fn try_from(value: ValueBytes) -> Result<Self, Self::Error> {
match value.0 {
Some(v) => Ok(v),
None => Err(crate::Error::Message("Value is None!".into())),
}
}
}