[][src]Struct jsonapi::api::JsonApiDocument

pub struct JsonApiDocument {
    pub data: Option<PrimaryData>,
    pub included: Option<Resources>,
    pub links: Option<Links>,
    pub meta: Option<Meta>,
    pub errors: Option<JsonApiErrors>,
    pub jsonapi: Option<JsonApiInfo>,
}

The specification refers to this as a top-level document

Fields

data: Option<PrimaryData>included: Option<Resources>links: Option<Links>meta: Option<Meta>errors: Option<JsonApiErrors>jsonapi: Option<JsonApiInfo>

Methods

impl JsonApiDocument[src]

Top-level JSON-API Document

pub fn is_valid(&self) -> bool[src]

This function returns false if the JsonApiDocument contains any violations of the specification. See DocumentValidationError

The spec dictates that the document must have least one of data, errors or meta. Of these, data and errors must not co-exist. The optional field included may only be present if the data field is present too.

use jsonapi::api::{JsonApiDocument, PrimaryData, JsonApiErrors};
let doc = JsonApiDocument {
    data: Some(PrimaryData::None),
    errors: Some(JsonApiErrors::new()),
    ..Default::default()
};

assert_eq!(doc.is_valid(), false);

pub fn validate(&self) -> Option<Vec<DocumentValidationError>>[src]

This function returns a Vec with identified specification violations enumerated in DocumentValidationError

use jsonapi::api::{JsonApiDocument, PrimaryData, JsonApiErrors, DocumentValidationError};

let doc = JsonApiDocument {
    data: Some(PrimaryData::None),
    errors: Some(JsonApiErrors::new()),
    ..Default::default()
};

match doc.validate() {
  Some(errors) => {
    assert!(
      errors.contains(
        &DocumentValidationError::DataWithErrors
      )
    )
  }
  None => assert!(false)
}

Trait Implementations

impl Default for JsonApiDocument[src]

impl Clone for JsonApiDocument[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq<JsonApiDocument> for JsonApiDocument[src]

impl Debug for JsonApiDocument[src]

impl FromStr for JsonApiDocument[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self>[src]

Instantiate from string

use jsonapi::api::JsonApiDocument;
use std::str::FromStr;

let serialized = r#"{
  "data" : [
    { "id":"1", "type":"post", "attributes":{}, "relationships":{}, "links" :{} },
    { "id":"2", "type":"post", "attributes":{}, "relationships":{}, "links" :{} },
    { "id":"3", "type":"post", "attributes":{}, "relationships":{}, "links" :{} }
  ]
}"#;
let doc = JsonApiDocument::from_str(&serialized);
assert_eq!(doc.is_ok(), true);

impl Serialize for JsonApiDocument[src]

impl<'de> Deserialize<'de> for JsonApiDocument[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]