[][src]Struct jsonapi::api::Resource

pub struct Resource {
    pub _type: String,
    pub id: JsonApiId,
    pub attributes: ResourceAttributes,
    pub relationships: Option<Relationships>,
    pub links: Option<Links>,
    pub meta: Option<Meta>,
}

Representation of a JSON:API resource. This is a struct that contains attributes that map to the JSON:API specification of id, type, attributes, relationships, links, and meta

Fields

_type: Stringid: JsonApiIdattributes: ResourceAttributesrelationships: Option<Relationships>links: Option<Links>meta: Option<Meta>

Methods

impl Resource[src]

pub fn get_relationship(&self, name: &str) -> Option<&Relationship>[src]

pub fn get_attribute(&self, name: &str) -> Option<&JsonApiValue>[src]

Get an attribute JsonApiValue

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

let serialized = r#"{
  "id":"1",
  "type":"post",
  "attributes":{
    "title": "Rails is Omakase",
    "likes": 250
  },
  "relationships":{},
  "links" :{}
}"#;

match Resource::from_str(&serialized) {
  Err(_)=> assert!(false),
  Ok(resource)=> {
    match resource.get_attribute("title") {
      None => assert!(false),
      Some(attr) => {
        match attr.as_str() {
          None => assert!(false),
          Some(s) => {
              assert_eq!(s, "Rails is Omakase");
          }
        }
      }
    }
  }
}

pub fn diff(&self, other: Resource) -> Result<PatchSet, DiffPatchError>[src]

pub fn patch(&mut self, patchset: PatchSet) -> Result<Resource>[src]

Trait Implementations

impl Clone for Resource[src]

impl Debug for Resource[src]

impl Default for Resource[src]

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

impl FromStr for Resource[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::Resource;
use std::str::FromStr;

let serialized = r#"{
  "id":"1",
  "type":"post",
  "attributes":{
    "title": "Rails is Omakase",
    "likes": 250
  },
  "relationships":{},
  "links" :{}
}"#;

let data = Resource::from_str(&serialized);
assert_eq!(data.is_ok(), true);

impl PartialEq<Resource> for Resource[src]

impl Serialize for Resource[src]

impl StructuralPartialEq for Resource[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> DeserializeOwned for T where
    T: Deserialize<'de>, 
[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.