pub struct Dictionary<'a> { /* private fields */ }Expand description
A validated Dictionary. Every member is kept in order; a repeated key’s
last value wins in get and index_into.
§Examples
use parse_net::sfv::{self, BareItem, Member};
let d = sfv::parse_dictionary(b"a=1, b")?;
assert_eq!(d.len(), 2);
assert!(matches!(d.get("b"), Some(Member::Item(i)) if i.bare == BareItem::Boolean(true)));Implementations§
Source§impl Dictionary<'_>
impl Dictionary<'_>
Sourcepub fn to_owned(&self) -> OwnedDictionary
Available on crate feature alloc only.
pub fn to_owned(&self) -> OwnedDictionary
alloc only.Copies the dictionary (one allocation).
§Examples
use parse_net::sfv;
let d = sfv::parse_dictionary(b"a=1, b")?;
assert_eq!(d.to_owned().as_view(), d);Source§impl<'a> Dictionary<'a>
impl<'a> Dictionary<'a>
Sourcepub fn iter(&self) -> DictIter<'a> ⓘ
pub fn iter(&self) -> DictIter<'a> ⓘ
The members with their keys, in order (repeats included).
§Examples
use parse_net::sfv;
let d = sfv::parse_dictionary(b"a=1, b=2, a=3")?;
assert!(d.iter().map(|(k, _)| k).eq(["a", "b", "a"]));Sourcepub fn get(&self, key: &str) -> Option<Member<'a>>
pub fn get(&self, key: &str) -> Option<Member<'a>>
The member for key: the last occurrence.
§Examples
use parse_net::sfv::{self, BareItem, Member};
let d = sfv::parse_dictionary(b"a=1, b=(x y)")?;
assert!(matches!(d.get("b"), Some(Member::InnerList(l)) if l.len() == 2));
assert!(d.get("c").is_none());Sourcepub fn index_into<'i>(
&self,
slots: &'i mut [(&'a str, Member<'a>)],
) -> Result<&'i [(&'a str, Member<'a>)], ParseError>
pub fn index_into<'i>( &self, slots: &'i mut [(&'a str, Member<'a>)], ) -> Result<&'i [(&'a str, Member<'a>)], ParseError>
Fills slots with one entry per distinct key (the last value for a
repeated key), in first-seen order, and returns the filled part: for
callers that look up many keys.
§Errors
ErrorKind::BufferTooSmall when there are more distinct keys than
slots.
§Examples
use parse_net::sfv::{self, BareItem, Item, Member};
let d = sfv::parse_dictionary(b"a=1, b=2, a=3")?;
let mut slots = [("", Member::Item(Item::new(BareItem::Boolean(false)))); 4];
let index = d.index_into(&mut slots)?;
assert_eq!(index.len(), 2);
assert!(matches!(index[0], ("a", Member::Item(i)) if i.bare == BareItem::Integer(3)));Trait Implementations§
Source§impl<'a> Clone for Dictionary<'a>
impl<'a> Clone for Dictionary<'a>
impl<'a> Copy for Dictionary<'a>
Source§impl<'a> Debug for Dictionary<'a>
impl<'a> Debug for Dictionary<'a>
impl<'a> Eq for Dictionary<'a>
Source§impl<'a> Hash for Dictionary<'a>
impl<'a> Hash for Dictionary<'a>
Source§impl<'a> PartialEq for Dictionary<'a>
impl<'a> PartialEq for Dictionary<'a>
impl<'a> StructuralPartialEq for Dictionary<'a>
Auto Trait Implementations§
impl<'a> Freeze for Dictionary<'a>
impl<'a> RefUnwindSafe for Dictionary<'a>
impl<'a> Send for Dictionary<'a>
impl<'a> Sync for Dictionary<'a>
impl<'a> Unpin for Dictionary<'a>
impl<'a> UnsafeUnpin for Dictionary<'a>
impl<'a> UnwindSafe for Dictionary<'a>
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