[][src]Struct in_toto::interchange::JsonPretty

pub struct JsonPretty;

Pretty JSON data interchange.

This is identical to Json in all manners except for the to_writer method. Instead of writing the metadata in the canonical format, it instead pretty prints the metadata.

Trait Implementations

impl Clone for JsonPretty[src]

impl DataInterchange for JsonPretty[src]

type RawData = Value

The type of data that is contained in the signed portion of metadata.

fn extension() -> &'static str[src]

assert_eq!(JsonPretty::extension(), "json");

fn canonicalize(raw_data: &Self::RawData) -> Result<Vec<u8>>[src]

let jsn: &[u8] = br#"{"foo": "bar", "baz": "quux"}"#;
let raw = JsonPretty::from_reader(jsn).unwrap();
let out = JsonPretty::canonicalize(&raw).unwrap();
assert_eq!(out, br#"{"baz":"quux","foo":"bar"}"#);

fn deserialize<T>(raw_data: &Self::RawData) -> Result<T> where
    T: DeserializeOwned
[src]

#[derive(Deserialize, Debug, PartialEq)]
struct Thing {
   foo: String,
   bar: String,
}

let jsn = json!({"foo": "wat", "bar": "lol"});
let thing = Thing { foo: "wat".into(), bar: "lol".into() };
let de: Thing = JsonPretty::deserialize(&jsn).unwrap();
assert_eq!(de, thing);

fn serialize<T>(data: &T) -> Result<Self::RawData> where
    T: Serialize
[src]

#[derive(Serialize)]
struct Thing {
   foo: String,
   bar: String,
}

let jsn = json!({"foo": "wat", "bar": "lol"});
let thing = Thing { foo: "wat".into(), bar: "lol".into() };
let se: serde_json::Value = JsonPretty::serialize(&thing).unwrap();
assert_eq!(se, jsn);

fn to_writer<W, T: Sized>(writer: W, value: &T) -> Result<()> where
    W: Write,
    T: Serialize
[src]

let json = json!({
    "o": {
        "a": [1, 2, 3],
        "s": "string",
        "n": 123,
        "t": true,
        "f": false,
        "0": null,
    },
});
let mut buf = Vec::new();
JsonPretty::to_writer(&mut buf, &json).unwrap();
assert_eq!(&String::from_utf8(buf).unwrap(), r#"{
  "o": {
    "0": null,
    "a": [
      1,
      2,
      3
    ],
    "f": false,
    "n": 123,
    "s": "string",
    "t": true
  }
}"#);

fn from_reader<R, T>(rdr: R) -> Result<T> where
    R: Read,
    T: DeserializeOwned
[src]

let jsn: &[u8] = br#"{"foo": "bar", "baz": "quux"}"#;
let _: HashMap<String, String> = JsonPretty::from_reader(jsn).unwrap();

fn from_slice<T>(slice: &[u8]) -> Result<T> where
    T: DeserializeOwned
[src]

let jsn: &[u8] = br#"{"foo": "bar", "baz": "quux"}"#;
let _: HashMap<String, String> = JsonPretty::from_slice(&jsn).unwrap();

impl Debug for JsonPretty[src]

impl PartialEq<JsonPretty> for JsonPretty[src]

impl StructuralPartialEq for JsonPretty[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,