mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
41 lines
819 B
Rust
41 lines
819 B
Rust
use json::JsonValue;
|
|
|
|
pub trait ToJson {
|
|
fn to_json(&self) -> Option<JsonValue>;
|
|
}
|
|
|
|
impl ToJson for &str {
|
|
fn to_json(&self) -> Option<JsonValue> {
|
|
Some(JsonValue::String(String::from(*self)))
|
|
}
|
|
}
|
|
|
|
impl ToJson for &String {
|
|
fn to_json(&self) -> Option<JsonValue> {
|
|
Some(JsonValue::String((*self).to_string()))
|
|
}
|
|
}
|
|
|
|
impl ToJson for String {
|
|
fn to_json(&self) -> Option<JsonValue> {
|
|
Some(JsonValue::String(self.to_string()))
|
|
}
|
|
}
|
|
|
|
impl ToJson for JsonValue {
|
|
fn to_json(&self) -> Option<JsonValue> {
|
|
Some(self.clone())
|
|
}
|
|
}
|
|
|
|
impl ToJson for &JsonValue {
|
|
fn to_json(&self) -> Option<JsonValue> {
|
|
Some((*self).clone())
|
|
}
|
|
}
|
|
|
|
pub trait FromJson where Self: Sized {
|
|
type Err;
|
|
fn from_json<T: ToJson>(v: T) -> Result<Self, Self::Err>;
|
|
}
|