Struct hateoas::RelLinkCollection
source · [−]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()));
Get RelLink from collection
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()));
Get Mutable RelLink from and updateing it.
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
sourceimpl RelLinkCollection
impl RelLinkCollection
sourcepub fn new(v_rel: Vec<RelLink>) -> Self
pub fn new(v_rel: Vec<RelLink>) -> Self
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![]);
sourcepub fn get(&self, rel: &str) -> Option<&RelLink>
pub fn get(&self, rel: &str) -> Option<&RelLink>
Get RelLink from Collection
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)));
sourcepub fn get_mut(&mut self, rel: &str) -> Option<&mut RelLink>
pub fn get_mut(&mut self, rel: &str) -> Option<&mut RelLink>
Get RelLink from Collection
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)));
sourcepub fn has(&self, rel: &str) -> bool
pub fn has(&self, rel: &str) -> bool
Has RelLink in Collection
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);
sourcepub fn add<I: Into<RelLink>>(&mut self, rel: I) -> Option<RelLink>
pub fn add<I: Into<RelLink>>(&mut self, rel: I) -> Option<RelLink>
Add RelLink to the collection
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
sourceimpl Debug for RelLinkCollection
impl Debug for RelLinkCollection
sourceimpl Default for RelLinkCollection
impl Default for RelLinkCollection
sourcefn default() -> RelLinkCollection
fn default() -> RelLinkCollection
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for RelLinkCollection
impl<'de> Deserialize<'de> for RelLinkCollection
sourcefn 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
sourceimpl<I: Into<RelLink>> From<I> for RelLinkCollection
impl<I: Into<RelLink>> From<I> for RelLinkCollection
sourceimpl From<RelLinkCollection> for Vec<RelLink>
impl From<RelLinkCollection> for Vec<RelLink>
sourcefn from(col: RelLinkCollection) -> Self
fn from(col: RelLinkCollection) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<RelLinkCollection> for RelLinkCollection
impl PartialEq<RelLinkCollection> for RelLinkCollection
sourcefn eq(&self, other: &RelLinkCollection) -> bool
fn eq(&self, other: &RelLinkCollection) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &RelLinkCollection) -> bool
fn ne(&self, other: &RelLinkCollection) -> bool
This method tests for !=
.
sourceimpl Serialize for RelLinkCollection
impl Serialize for RelLinkCollection
impl StructuralPartialEq for RelLinkCollection
Auto Trait Implementations
impl RefUnwindSafe for RelLinkCollection
impl Send for RelLinkCollection
impl Sync for RelLinkCollection
impl Unpin for RelLinkCollection
impl UnwindSafe for RelLinkCollection
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more