[−][src]Struct jsonapi::api::Resource
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: String
id: JsonApiId
attributes: ResourceAttributes
relationships: 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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralPartialEq for Resource
[src]
Auto Trait Implementations
impl RefUnwindSafe for Resource
impl Send for Resource
impl Sync for Resource
impl Unpin for Resource
impl UnwindSafe for Resource
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,