pub struct RelLinkCollection(/* private fields */);
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§
Source§impl 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§
Source§impl Debug for RelLinkCollection
impl Debug for RelLinkCollection
Source§impl Default for RelLinkCollection
impl Default for RelLinkCollection
Source§fn default() -> RelLinkCollection
fn default() -> RelLinkCollection
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for RelLinkCollection
impl<'de> Deserialize<'de> for RelLinkCollection
Source§fn 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
Source§impl From<RelLinkCollection> for Vec<RelLink>
impl From<RelLinkCollection> for Vec<RelLink>
Source§fn from(col: RelLinkCollection) -> Self
fn from(col: RelLinkCollection) -> Self
Converts to this type from the input type.
Source§impl PartialEq for RelLinkCollection
impl PartialEq for RelLinkCollection
Source§impl Serialize for RelLinkCollection
impl Serialize for RelLinkCollection
impl StructuralPartialEq for RelLinkCollection
Auto Trait Implementations§
impl Freeze for RelLinkCollection
impl RefUnwindSafe for RelLinkCollection
impl Send for RelLinkCollection
impl Sync for RelLinkCollection
impl Unpin for RelLinkCollection
impl UnwindSafe for RelLinkCollection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more