mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-04-25 07:27:01 -05:00
value: add TryFrom implementations for Cow<'_, str>
This commit is contained in:
parent
bf9f8e60c7
commit
65f7bfed9a
|
|
@ -1,3 +1,4 @@
|
|||
use std::borrow::Cow;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::io::Cursor;
|
||||
|
|
@ -461,6 +462,34 @@ impl TryFrom<&Value> for Vec<u8> {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Value> for Cow<'_, str> {
|
||||
type Error = KbinError;
|
||||
|
||||
fn try_from(value: Value) -> Result<Self> {
|
||||
match value {
|
||||
Value::String(v) => Ok(Cow::Owned(v)),
|
||||
value => Err(KbinError::ValueTypeMismatch {
|
||||
node_type: StandardType::String,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Value> for Cow<'_, str> {
|
||||
type Error = KbinError;
|
||||
|
||||
fn try_from(value: &Value) -> Result<Self> {
|
||||
match value {
|
||||
Value::String(ref v) => Ok(Cow::Owned(v.clone())),
|
||||
value => Err(KbinError::ValueTypeMismatch {
|
||||
node_type: StandardType::String,
|
||||
value: value.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for Value {
|
||||
fn from(value: Vec<u8>) -> Value {
|
||||
Value::Binary(value)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user