Struct vnd_siren::entity::Entity

source ·
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

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(),
);

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());

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());

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());

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();

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();

Returns a reference to the Entity’s rel vector.

Examples
let entity: Entity = Entity::builder()
    .rel(vec!["http://x.io/rels/customer"]).into();
 
assert_eq!(&Some(vec!["http://x.io/rels/customer".to_string()]), entity.rel());

Returns a reference to the Entity’s title.

Examples
let entity: Entity = Entity::builder()
    .title("example").into();
 
assert_eq!(&Some("example".to_string()), entity.title());

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.