[−][src]Struct jsonapi::api::JsonApiDocument
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 Clone for JsonApiDocument
[src]
fn clone(&self) -> JsonApiDocument
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for JsonApiDocument
[src]
fn default() -> JsonApiDocument
[src]
impl PartialEq<JsonApiDocument> for JsonApiDocument
[src]
fn eq(&self, other: &JsonApiDocument) -> bool
[src]
fn ne(&self, other: &JsonApiDocument) -> bool
[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 StructuralPartialEq for JsonApiDocument
[src]
impl Serialize for JsonApiDocument
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for JsonApiDocument
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Send for JsonApiDocument
impl Sync for JsonApiDocument
impl Unpin for JsonApiDocument
impl UnwindSafe for JsonApiDocument
impl RefUnwindSafe for JsonApiDocument
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,