JSON

Trait JSON 

Source
pub trait JSON<'a>: Serialize + Deserialize<'a> {
    // Provided methods
    fn parse<T: AsRef<str>>(&mut self, s: &'a T) -> Result<(), Error> { ... }
    fn to_string(&self) -> String { ... }
    fn stringify(&self, indent: usize) -> String { ... }
    fn read<F: AsRef<Path>>(
        &mut self,
        file: F,
        content: &'a mut String,
    ) -> Result<(), String> { ... }
    fn write<F: AsRef<Path>>(&self, file: F) -> Result<()> { ... }
}

Provided Methods§

Source

fn parse<T: AsRef<str>>(&mut self, s: &'a T) -> Result<(), Error>

Parse JSON from string

Source

fn to_string(&self) -> String

Return a concise JSON string

Source

fn stringify(&self, indent: usize) -> String

Stringify a native-json object

indent

  • 0 : output concise JSON string
  • N : pretty output with N spaces indentation
Source

fn read<F: AsRef<Path>>( &mut self, file: F, content: &'a mut String, ) -> Result<(), String>

Deserialize JSON from file

Due to the serde lifetime issue, the content should have same lifetime as the JSON object itself, the content will be borrowed as mutable zoombie.

Source

fn write<F: AsRef<Path>>(&self, file: F) -> Result<()>

Serialize JSON into file

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.

Implementors§

Source§

impl<'a, T> JSON<'a> for T
where T: Serialize + Deserialize<'a>,