Struct jsonapi_rs::api::Resource
source · pub struct Resource {
pub _type: String,
pub id: JsonApiId,
pub attributes: ResourceAttributes,
pub relationships: Option<Relationships>,
pub links: Option<Links>,
pub meta: Option<Meta>,
}
Expand description
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>
Implementations§
source§impl Resource
impl Resource
pub fn get_relationship(&self, name: &str) -> Option<&Relationship>
sourcepub fn get_attribute(&self, name: &str) -> Option<&JsonApiValue>
pub fn get_attribute(&self, name: &str) -> Option<&JsonApiValue>
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>
pub fn patch(&mut self, patchset: PatchSet) -> Result<Resource>
Trait Implementations§
source§impl<'de> Deserialize<'de> for Resource
impl<'de> Deserialize<'de> for Resource
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl FromStr for Resource
impl FromStr for Resource
source§fn from_str(s: &str) -> Result<Self>
fn from_str(s: &str) -> Result<Self>
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);
source§impl PartialEq for Resource
impl PartialEq for Resource
impl StructuralPartialEq for Resource
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more