Add From impls
This commit is contained in:
parent
1deb8981ff
commit
26c56f9287
1 changed files with 28 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use std::borrow::Cow;
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
|
|
@ -57,6 +58,30 @@ impl From<NumberOrString> for JsValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<i64> for NumberOrString {
|
||||
fn from(value: i64) -> Self {
|
||||
NumberOrString::Number(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for NumberOrString {
|
||||
fn from(value: String) -> Self {
|
||||
NumberOrString::Text(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for NumberOrString {
|
||||
fn from(value: &str) -> Self {
|
||||
NumberOrString::Text(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Cow<'a, str>> for NumberOrString {
|
||||
fn from(value: Cow<'a, str>) -> Self {
|
||||
NumberOrString::Text(value.into_owned())
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type for deserialisation failures
|
||||
#[cfg(feature = "wasm")]
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -85,5 +110,7 @@ impl std::error::Error for DeserialisationError {}
|
|||
|
||||
#[cfg(feature = "wasm")]
|
||||
impl From<DeserialisationError> for JsValue {
|
||||
fn from(error: DeserialisationError) -> Self { JsValue::from_str(&error.message) }
|
||||
fn from(error: DeserialisationError) -> Self {
|
||||
JsValue::from_str(&error.message)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue