Struct vnd_siren::action::Action

source ·
pub struct Action {
    pub class: Option<Vec<String>>,
    pub fields: Option<Vec<Field>>,
    pub name: String,
    pub href: String,
    pub method: Option<Method>,
    pub title: Option<String>,
    pub typ: Option<String>,
}
Expand description

Actions show available behaviors an entity exposes.

Fields

class: Option<Vec<String>>

Describes the nature of an action based on the current representation. Possible values are implementation-dependent and should be documented.

fields: Option<Vec<Field>>

A collection of fields, expressed as an array of objects in JSON Siren such as { "fields" : [{ ... }] }.

name: String

A string that identifies the action to be performed. Action names MUST be unique within the set of actions for an entity. The behavior of clients when parsing a Siren document that violates this constraint is undefined.

href: String

The URI of the action.

method: Option<Method>

An enumerated attribute mapping to a protocol method. For HTTP, these values may be GET, PUT, POST, DELETE, or PATCH. As new methods are introduced, this list can be extended. If this attribute is omitted, GET should be assumed.

title: Option<String>

Descriptive text about the action.

typ: Option<String>

The encoding type for the request. When omitted and the fields attribute exists, the default value is application/x-www-form-urlencoded.

Implementations

Create a Action builder with the given name and href.

Examples
let action = Action::builder("add-item", "http://api.x.io/orders/42/items");

Returns a reference to the Action’s Classes.

Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
    .classes(vec!["item"]).into();
 
assert_eq!(&Some(vec!["item".to_string()]), action.classes());

Returns a reference to the Action’s Fields.

Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
    .fields(vec![
        Field::builder("orderNumber").typ("hidden").value("42"),
        Field::builder("productCode").typ("text"),
        Field::builder("quantity").typ("number"),
    ]).into();
 
assert_eq!(
    &Some(vec![
        Field::builder("orderNumber").typ("hidden").value("42").into(),
        Field::builder("productCode").typ("text").into(),
        Field::builder("quantity").typ("number").into(),
    ]),
    action.fields(),
);

Returns a reference to the Action’s Method.

Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
    .method(Method::Post).into();
 
assert_eq!(&Some(Method::Post), action.method());

Returns a reference to the Action’s title.

Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
    .title("Add Item").into();
 
assert_eq!(&Some("Add Item".to_string()), action.title());

Returns a reference to the Action’s type.

Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
    .typ("application/x-www-form-urlencoded").into();
 
assert_eq!(&Some("application/x-www-form-urlencoded".to_string()), action.typ());

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.