pub struct Fields { /* private fields */ }
Expand description
Mapping of names to Field
s.
Implementations§
Source§impl Fields
impl Fields
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return whether this field map contains no fields.
let mut fields = Fields::default();
assert!(fields.is_empty());
fields.insert("", Field::empty());
assert!(!fields.is_empty());
Sourcepub fn contains(&self, name: impl AsRef<str>) -> bool
pub fn contains(&self, name: impl AsRef<str>) -> bool
Return whether this field map contains a field with the given name.
let fields: Fields = [("a thing", Field::empty())].into_iter().collect();
assert!(fields.contains("a thing"));
assert!(!fields.contains("not a thing"));
Sourcepub fn get(&self, name: impl AsRef<str>) -> Option<&Field>
pub fn get(&self, name: impl AsRef<str>) -> Option<&Field>
Get a reference to the field with the provided name
, if it exists.
let fields: Fields = [("a thing", Field::empty())].into_iter().collect();
assert!(fields.get("a thing").is_some());
assert!(fields.get("not a thing").is_none());
Sourcepub fn get_mut(&mut self, name: impl AsRef<str>) -> Option<&mut Field>
pub fn get_mut(&mut self, name: impl AsRef<str>) -> Option<&mut Field>
Get a mutable reference to the field with the provided name
, if it exists.
let mut fields: Fields = [("a thing", Field::empty())].into_iter().collect();
assert!(fields.get_mut("a thing").is_some());
assert!(fields.get_mut("not a thing").is_none());
Sourcepub fn insert(&mut self, name: impl Into<String>, field: Field) -> Option<Field>
pub fn insert(&mut self, name: impl Into<String>, field: Field) -> Option<Field>
Insert a field with the given name into the map.
let mut fields = Fields::default();
assert!(fields.insert("field", Field::empty()).is_none());
assert!(fields.insert("field", Field::empty()).is_some());
Sourcepub fn remove(&mut self, name: impl AsRef<str>) -> Option<Field>
pub fn remove(&mut self, name: impl AsRef<str>) -> Option<Field>
Remove a field with the given name from the map.
let mut fields: Fields = [("a", Field::empty())].into_iter().collect();
assert_eq!(fields.remove("a"), Some(Field::empty()));
assert_eq!(fields.remove("a"), None);
Sourcepub fn field(&mut self, name: impl Into<String>) -> &mut Field
pub fn field(&mut self, name: impl Into<String>) -> &mut Field
Get a mutable reference to the field with the provided name
,
inserting an empty Field
if it didn’t exist.
let mut fields = Fields::default();
assert!(!fields.contains("thing"));
fields.field("thing");
assert!(fields.contains("thing"));
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Fields
impl<'de> Deserialize<'de> for Fields
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
impl Eq for Fields
impl StructuralPartialEq for Fields
Auto Trait Implementations§
impl Freeze for Fields
impl RefUnwindSafe for Fields
impl Send for Fields
impl Sync for Fields
impl Unpin for Fields
impl UnwindSafe for Fields
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