pub struct Entity {
pub actions: Option<Vec<Action>>,
pub class: Option<Vec<String>>,
pub entities: Option<Vec<Box<Entity>>>,
pub href: Option<String>,
pub links: Option<Vec<Link>>,
pub properties: Option<HashMap<String, Value>>,
pub rel: Option<Vec<String>>,
pub title: Option<String>,
}
Expand description
An Entity is a URI-addressable resource that has properties and actions associated with it. It may contain sub-entities and navigational links.
Root entities and sub-entities that are embedded representations SHOULD contain a links
collection with at least one item contain a rel
value of self
and an href
attribute with a value of the entity’s URI.
Sub-entities that are embedded links MUST contain an href
attribute with a value of its URI.
Fields
actions: Option<Vec<Action>>
A collection of action objects, represented in JSON Siren as an array such as { "actions": [{ ... }] }
.
class: Option<Vec<String>>
Describes the nature of an entity’s content based on the current representation. Possible values are implementation-dependent and should be documented.
entities: Option<Vec<Box<Entity>>>
A collection of related sub-entities. If a sub-entity contains an href
value, it should be treated as an embedded link.
Clients may choose to optimistically load embedded links.
If no href
value exists, the sub-entity is an embedded entity representation that contains all the characteristics of a typical entity.
One difference is that a sub-entity MUST contain a rel
attribute to describe its relationship to the parent entity.
href: Option<String>
The URI of the linked sub-entity.
links: Option<Vec<Link>>
A collection of items that describe navigational links, distinct from entity relationships.
Link items should contain a rel
attribute to describe the relationship and an href attribute to point to the target URI.
Entities should include a link rel
to self
.
In JSON Siren, this is represented as "links": [{ "rel": ["self"], "href": "http://api.x.io/orders/1234" }]
.
properties: Option<HashMap<String, Value>>
A set of key-value pairs that describe the state of an entity.
In JSON Siren, this is an object such as { "name": "Kevin", "age": 30 }
.
rel: Option<Vec<String>>
Defines the relationship of the sub-entity to its parent, per Web Linking (RFC5988) and Link Relations.
title: Option<String>
Descriptive text about the entity.
Implementations
sourceimpl Entity
impl Entity
pub fn builder() -> EntityBuilder
sourcepub fn actions(&self) -> &Option<Vec<Action>>
pub fn actions(&self) -> &Option<Vec<Action>>
Returns a reference to the Entity’s Actions.
Examples
let entity: Entity = Entity::builder()
.actions(vec![
Action::builder("add-item", "http://api.x.io/orders/42/items"),
]).into();
assert_eq!(
&Some(vec![
Action::builder("add-item", "http://api.x.io/orders/42/items").into(),
]),
entity.actions(),
);
sourcepub fn classes(&self) -> &Option<Vec<String>>
pub fn classes(&self) -> &Option<Vec<String>>
Returns a reference to the Entity’s classes.
Examples
let entity: Entity = Entity::builder()
.classes(vec!["item"]).into();
assert_eq!(&Some(vec!["item".to_string()]), entity.classes());
sourcepub fn entities(&self) -> &Option<Vec<Box<Entity>>>
pub fn entities(&self) -> &Option<Vec<Box<Entity>>>
Returns a reference to the Entity’s Entities.
Examples
let entity: Entity = Entity::builder()
.entities(vec![Entity::builder()]).into();
assert_eq!(&Some(vec![Box::new(Entity::builder().into())]), entity.entities());
sourcepub fn href(&self) -> &Option<String>
pub fn href(&self) -> &Option<String>
Returns a reference to the Entity’s href.
Examples
let entity: Entity = Entity::builder()
.href("http://api.x.io/orders/42/items").into();
assert_eq!(&Some("http://api.x.io/orders/42/items".to_string()), entity.href());
sourcepub fn links(&self) -> &Option<Vec<Link>>
pub fn links(&self) -> &Option<Vec<Link>>
Returns a reference to the Entity’s Links.
Examples
let entity: Entity = Entity::builder()
.links(vec![
Link::builder(vec!["self"], "http://api.x.io/customers/pj123")
]).into();
sourcepub fn properties(&self) -> &Option<HashMap<String, Value>>
pub fn properties(&self) -> &Option<HashMap<String, Value>>
Returns a reference to the Entity’s Properties.
Examples
let entity: Entity = Entity::builder()
.properties(vec![
Property::new("customerId", "pj123"),
Property::new("name", "Peter Joseph"),
]).into();