pub struct RelLinkCollection(_);
Expand description

RelLinkCollection

Adding new data to the collection

use hateoas::{HttpMethod, RelLink, RelLinkCollection};

let rel_vec = vec![
    RelLink::new( "foo","foo", HttpMethod::Get),
    RelLink::new( "bar","bar", HttpMethod::Get)
];
let rlc_check = RelLinkCollection::new(rel_vec);

let mut rlc = RelLinkCollection::default();
rlc.add(RelLink::new( "foo","foo", HttpMethod::Get));
rlc.add(RelLink::new( "bar","bar", HttpMethod::Get));

Adding new data but data is overwritten

use hateoas::{HttpMethod, RelLink, RelLinkCollection};

let rel_vec = vec![
    RelLink::new( "foo","foo", HttpMethod::Get),
    RelLink::new( "bar","bar", HttpMethod::Get)
];
let mut rlc = RelLinkCollection::new(rel_vec);

let old_rel = rlc.add(RelLink::new( "foo","foo-bar", HttpMethod::Get));

assert_eq!(old_rel, Some(("foo", "foo", HttpMethod::Get).into()));
use hateoas::{HttpMethod, RelLink, RelLinkCollection};

let rel_vec = vec![
    RelLink::new( "foo","foo", HttpMethod::Get),
    RelLink::new( "bar","bar", HttpMethod::Get)
];
let mut rlc = RelLinkCollection::new(rel_vec);

let rel = rlc.get("foo");

assert_eq!(rel, Some(&("foo", "foo", HttpMethod::Get).into()));
use hateoas::{HttpMethod, RelLink, RelLinkCollection};

let rel_vec = vec![
    RelLink::new( "foo","foo", HttpMethod::Get),
    RelLink::new( "bar","bar", HttpMethod::Get)
];
let mut rlc = RelLinkCollection::new(rel_vec);

let mut rel = rlc.get_mut("foo");

assert_eq!(rel, Some(&mut ("foo", "foo", HttpMethod::Get).into()));

rel.map(|t| *t = ("foo-bar", "foo-bar", HttpMethod::Connect).into());

let updated_rel = rlc.get("foo-bar");

assert_eq!(updated_rel, Some(&("foo-bar", "foo-bar", HttpMethod::Connect).into()));

Implementations

Create Collection

Create new Collection with complete Vec, this allows to set all the elements for the collection in one go using a Vec.

use hateoas::{RelLink, RelLinkCollection};

let collection = RelLinkCollection::new(vec![]);
let vec_col: Vec<RelLink> = collection.into();

assert_eq!(vec_col, vec![]);

Getting a RelLink from the collection by rel id.

use hateoas::{RelLinkCollection, HttpMethod, RelLink};

let collection = RelLinkCollection::new(vec![("rel_id", "/rel_path/", HttpMethod::Get).into()]);

assert_eq!(collection.get("rel_id"), Some(&RelLink::new("rel_id", "/rel_path/", HttpMethod::Get)));

Getting a RelLink from the collection by rel id.

use hateoas::{RelLinkCollection, HttpMethod, RelLink};

let mut collection = RelLinkCollection::new(vec![("rel_id", "/rel_path/", HttpMethod::Get).into()]);
let mut rel_from_collection = collection.get_mut("rel_id");
rel_from_collection.map(|t| *t = RelLink::new("rel_id_2", "/rel_path_2/", HttpMethod::Connect));

assert_eq!(collection.get("rel_id_2"), Some(&RelLink::new("rel_id_2", "/rel_path_2/", HttpMethod::Connect)));

Checking if a rel_id already exists in the collection.

use hateoas::{RelLinkCollection, HttpMethod, RelLink};

let mut collection = RelLinkCollection::new(vec![("rel_id", "/rel_path/", HttpMethod::Get).into()]);

assert_eq!(collection.has("rel_id"), true);
assert_eq!(collection.has("rel_id_2"), false);

Adding a link to the collection of RelLinks, if the link already exists it will insert the new data and return the old.

use hateoas::{RelLinkCollection, HttpMethod, RelLink};

let mut collection = RelLinkCollection::new(vec![("rel_id", "/rel_path/", HttpMethod::Get).into()]);
let old_data = collection.add(("rel_id", "/rel_path_2/", HttpMethod::Connect));

assert_eq!(old_data, Some(RelLink::new("rel_id", "/rel_path/", HttpMethod::Get)));
assert_eq!(collection.get("rel_id"), Some(&RelLink::new("rel_id", "/rel_path_2/", HttpMethod::Connect)));

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Converts to this type from the input type.

Converts to this type from the input type.

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 !=.

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 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.