pub struct XmlHashTableRef<'a, T>(/* private fields */);Implementations§
Source§impl<'a, T> XmlHashTableRef<'a, T>
impl<'a, T> XmlHashTableRef<'a, T>
pub fn new() -> Option<Self>
pub fn with_capacity(size: usize) -> Option<Self>
pub fn from_table(table: XmlHashTable<'a, T>) -> Option<Self>
pub fn as_ptr<'b>(self) -> *mut XmlHashTable<'b, T>where
'a: 'b,
pub fn into_inner(self) -> XmlHashTable<'a, T>
pub fn free(self)
Methods from Deref<Target = XmlHashTable<'a, T>>§
pub fn clear(&mut self)
pub fn clear_with(&mut self, deallocator: impl Fn(T, Option<Cow<'_, str>>))
Sourcepub fn update_entry(
&mut self,
name: &str,
data: T,
deallocator: impl FnMut(T, Option<Cow<'_, str>>),
) -> Result<(), Error>
pub fn update_entry( &mut self, name: &str, data: T, deallocator: impl FnMut(T, Option<Cow<'_, str>>), ) -> Result<(), Error>
Update a entry specified by name with data.
Even if update does not occur, returns Ok as long as the execution is successfully completed.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("hoge", 1u32);
table.add_entry2("foo", Some("bar"), 2);
// Update occurs.
let mut updated = false;
assert!(table.update_entry("hoge", 2, |data, name| {
assert_eq!(data, 1);
assert_eq!(name.unwrap().as_ref(), "hoge");
updated = true;
}).is_ok());
assert!(updated);
table.update_entry("hoge", 3, |data, _| assert_eq!(data, 2));
// Update does not occur, but execution is successfully completed.
let mut updated = false;
assert!(table.update_entry("foo", 3, |_, _| {
updated = true;
}).is_ok());
assert!(!updated);Sourcepub fn update_entry2(
&mut self,
name: &str,
name2: Option<&str>,
data: T,
deallocator: impl FnMut(T, Option<Cow<'_, str>>),
) -> Result<(), Error>
pub fn update_entry2( &mut self, name: &str, name2: Option<&str>, data: T, deallocator: impl FnMut(T, Option<Cow<'_, str>>), ) -> Result<(), Error>
Update a entry specified by both name and name2 with data.
Even if update does not occur, returns Ok as long as the execution is successfully completed.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry2("foo", Some("bar"), 2u32);
table.add_entry3("hoge", Some("fuga"), Some("piyo"), 3);
let mut updated = false;
assert!(table.update_entry2("foo", Some("bar"), 3, |data, name| {
assert_eq!(data, 2);
assert_eq!(name.unwrap().as_ref(), "foo");
updated = true;
}).is_ok());
assert!(updated);
let mut updated = false;
assert!(table.update_entry2("hoge", Some("fuga"), 4, |_, _| {
updated = true;
}).is_ok());
assert!(!updated);Sourcepub fn update_entry3(
&mut self,
name: &str,
name2: Option<&str>,
name3: Option<&str>,
data: T,
deallocator: impl FnMut(T, Option<Cow<'_, str>>),
) -> Result<(), Error>
pub fn update_entry3( &mut self, name: &str, name2: Option<&str>, name3: Option<&str>, data: T, deallocator: impl FnMut(T, Option<Cow<'_, str>>), ) -> Result<(), Error>
Update a entry specified by all of name, name2 and name3 with data.
Even if update does not occur, returns Ok as long as the execution is successfully completed.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry3("hoge", Some("fuga"), Some("piyo"), 3);
let mut updated = false;
assert!(table.update_entry3("hoge", Some("fuga"), Some("piyo"), 4, |data, name| {
assert_eq!(data, 3);
assert_eq!(name.unwrap().as_ref(), "hoge");
updated = true;
}).is_ok());
assert!(updated);Sourcepub fn add_entry(&mut self, name: &str, data: T) -> Result<(), Error>
pub fn add_entry(&mut self, name: &str, data: T) -> Result<(), Error>
Add an entry specified name with data.
If some entries that have same name already exists or some error occurs, return Err,
otherwise return Ok.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
assert!(table.add_entry("foo", 1u32).is_ok());
// ("foo", 1) already exists, so `table` returns `Err`.
assert!(table.add_entry("foo", 2u32).is_err());
assert_eq!(table.lookup("foo"), Some(&1));Sourcepub fn add_entry2(
&mut self,
name: &str,
name2: Option<&str>,
data: T,
) -> Result<(), Error>
pub fn add_entry2( &mut self, name: &str, name2: Option<&str>, data: T, ) -> Result<(), Error>
Add an entry specified both name and name2 with data.
If some entries that have the same pair of names already exists or some error occurs, return Err,
otherwise return Ok.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
assert!(table.add_entry2("foo", Some("bar"), 1u32).is_ok());
// ("foo", "bar", 1) already exists, so `table` returns `Err`.
assert!(table.add_entry2("foo", Some("bar"), 2u32).is_err());
// "foo" already exists, but the pair of ("foo", "hoge") does not yet exist.
assert!(table.add_entry2("foo", Some("hoge"), 3u32).is_ok());
assert_eq!(table.lookup2("foo", Some("bar")), Some(&1));Sourcepub fn add_entry3(
&mut self,
name: &str,
name2: Option<&str>,
name3: Option<&str>,
data: T,
) -> Result<(), Error>
pub fn add_entry3( &mut self, name: &str, name2: Option<&str>, name3: Option<&str>, data: T, ) -> Result<(), Error>
Add an entry specified all of name, name2 and name3 with data.
If some entries that have the same pair of names already exists or some error occurs, return Err,
otherwise return Ok.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
assert!(table.add_entry3("foo", Some("bar"), Some("fuga"), 1u32).is_ok());
// ("foo", "bar", 1) already exists, so `table` returns `Err`.
assert!(table.add_entry3("foo", Some("bar"), Some("fuga"), 2u32).is_err());
// ("foo", "bar") already exists,
// but the pair of ("foo", "bar", "piyo") does not yet exist.
assert!(table.add_entry3("foo", Some("bar"), Some("piyo"), 3u32).is_ok());
assert_eq!(table.lookup3("foo", Some("bar"), Some("fuga")), Some(&1));Sourcepub fn remove_entry(
&mut self,
name: &str,
deallocator: impl Fn(T, Option<Cow<'_, str>>),
) -> Result<(), Error>
pub fn remove_entry( &mut self, name: &str, deallocator: impl Fn(T, Option<Cow<'_, str>>), ) -> Result<(), Error>
Remove the entry specified by name.
If such entry is found, deallocate the data with deallocator and return Ok,
otherwise return Err.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("hoge", 1);
table.add_entry2("hoge", Some("fuga"), 2);
assert!(table.remove_entry("hoge", |data, _| assert_eq!(data, 1)).is_ok());
// No entries match with "hoge" are found.
assert!(table.remove_entry("hoge", |_, _| {}).is_err());Sourcepub fn remove_entry2(
&mut self,
name: &str,
name2: Option<&str>,
deallocator: impl Fn(T, Option<Cow<'_, str>>),
) -> Result<(), Error>
pub fn remove_entry2( &mut self, name: &str, name2: Option<&str>, deallocator: impl Fn(T, Option<Cow<'_, str>>), ) -> Result<(), Error>
Remove the entry specified by both name and name2.
If such entry is found, deallocate the data with deallocator and return Ok,
otherwise return Err.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry2("hoge", Some("fuga"), 1);
table.add_entry3("hoge", Some("fuga"), Some("piyo"), 2);
assert!(table.remove_entry2("hoge", Some("fuga"), |data, _| assert_eq!(data, 1)).is_ok());
// No entries match with ("hoge", "fuga") are found.
assert!(table.remove_entry2("hoge", Some("fuga"), |_, _| {}).is_err());Sourcepub fn remove_entry3(
&mut self,
name: &str,
name2: Option<&str>,
name3: Option<&str>,
deallocator: impl Fn(T, Option<Cow<'_, str>>),
) -> Result<(), Error>
pub fn remove_entry3( &mut self, name: &str, name2: Option<&str>, name3: Option<&str>, deallocator: impl Fn(T, Option<Cow<'_, str>>), ) -> Result<(), Error>
Remove the entry specified by all of name, name2 and name3.
If such entry is found, deallocate the data with deallocator and return Ok,
otherwise return Err.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry3("hoge", Some("fuga"), Some("piyo"), 2);
assert!(table.remove_entry3("hoge", Some("fuga"), Some("piyo"), |data, _| assert_eq!(data, 2)).is_ok());Sourcepub fn lookup(&self, name: &str) -> Option<&T>
pub fn lookup(&self, name: &str) -> Option<&T>
Search the entry specified by name.
If such entry is found, return Some, otherwise return None.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("hoge", 1u32);
assert_eq!(table.lookup("hoge"), Some(&1));
assert_eq!(table.lookup("fuga"), None);Sourcepub fn lookup2(&self, name: &str, name2: Option<&str>) -> Option<&T>
pub fn lookup2(&self, name: &str, name2: Option<&str>) -> Option<&T>
Search the entry specified by both name and name2.
If such entry is found, return Some, otherwise return None.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry2("hoge", Some("fuga"), 1u32);
assert_eq!(table.lookup2("hoge", Some("fuga")), Some(&1));
assert_eq!(table.lookup2("hoge", Some("piyo")), None);Sourcepub fn lookup3(
&self,
name: &str,
name2: Option<&str>,
name3: Option<&str>,
) -> Option<&T>
pub fn lookup3( &self, name: &str, name2: Option<&str>, name3: Option<&str>, ) -> Option<&T>
Search the entry specified by all of name, name2 and name3.
If such entry is found, return Some, otherwise return None.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry3("hoge", Some("fuga"), Some("piyo"), 1u32);
assert_eq!(table.lookup3("hoge", Some("fuga"), Some("piyo")), Some(&1));
assert_eq!(table.lookup3("hoge", Some("fuga"), Some("bar")), None);Sourcepub fn qlookup(&self, prefix: Option<&str>, name: &str) -> Option<&T>
pub fn qlookup(&self, prefix: Option<&str>, name: &str) -> Option<&T>
Search the entry specified by the QName prefix:name.
If such entry is found, return Some, otherwise return None.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("hoge:fuga", 1u32);
// You can search QName by all of the following way.
assert_eq!(table.qlookup(Some("hoge"), "fuga"), Some(&1));
assert_eq!(table.qlookup(None, "hoge:fuga"), Some(&1));
assert_eq!(table.lookup("hoge:fuga"), Some(&1));
table.add_entry("hoge", 2);
assert_eq!(table.qlookup(None, "hoge"), Some(&2));Sourcepub fn qlookup2(
&self,
prefix: Option<&str>,
name: &str,
prefix2: Option<&str>,
name2: Option<&str>,
) -> Option<&T>
pub fn qlookup2( &self, prefix: Option<&str>, name: &str, prefix2: Option<&str>, name2: Option<&str>, ) -> Option<&T>
Search the entry specified by the given QNames.
If such entry is found, return Some, otherwise return None.
Please refer to the example for XmlHashTable::qlookup.
Sourcepub fn qlookup3(
&self,
prefix: Option<&str>,
name: &str,
prefix2: Option<&str>,
name2: Option<&str>,
prefix3: Option<&str>,
name3: Option<&str>,
) -> Option<&T>
pub fn qlookup3( &self, prefix: Option<&str>, name: &str, prefix2: Option<&str>, name2: Option<&str>, prefix3: Option<&str>, name3: Option<&str>, ) -> Option<&T>
Search the entry specified by the given QNames.
If such entry is found, return Some, otherwise return None.
Please refer to the example for XmlHashTable::qlookup.
Sourcepub fn clone_with(
&self,
copier: impl FnMut(&T, Option<&Cow<'a, str>>) -> T,
) -> Self
pub fn clone_with( &self, copier: impl FnMut(&T, Option<&Cow<'a, str>>) -> T, ) -> Self
Clone the table. copier is used for copying each data of entries.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("hoge", 1u32);
table.add_entry("fuga", 2);
table.add_entry("piyo", 3);
let cloned = table.clone_with(|data, _| data.clone());
let mut data = vec![];
cloned.scan(|d, name, _, _| data.push((*d, name.unwrap().as_ref().to_owned())));
data.sort();
assert_eq!(
data,
vec![
(1u32, "hoge".to_owned()),
(2, "fuga".to_owned()),
(3, "piyo".to_owned())
]
);Sourcepub fn remove_if(
&mut self,
cond: impl FnMut(&T, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>) -> bool,
deallocator: impl FnMut(T, Option<Cow<'a, str>>),
)
pub fn remove_if( &mut self, cond: impl FnMut(&T, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>) -> bool, deallocator: impl FnMut(T, Option<Cow<'a, str>>), )
Remove entries which cond returns true when its data, name, name2 and name3 are given.
Clone the table. copier is used for copying each data of entries.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("hoge", 1u32);
table.add_entry("fuga", 2);
table.add_entry("piyo", 3);
table.add_entry("foo", 4);
assert_eq!(table.len(), 4);
table.remove_if(|data, _, _, _| data % 2 == 0, |_, _| {});
assert_eq!(table.len(), 2);
assert!(table.lookup("hoge").is_some());
assert!(table.lookup("fuga").is_none());
assert!(table.lookup("piyo").is_some());
assert!(table.lookup("foo").is_none());§Note
In original libxml2, xmlHashScan/ScanFull allows a callback to modify the table being scanned,
but obviously this is not safe.
(Deletions would work fine, but additions and updates may not work well once the table rebuild runs.)
Therefore, no changes are allowed in the scan method.
Sourcepub fn scan(
&self,
f: impl FnMut(&T, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>),
)
pub fn scan( &self, f: impl FnMut(&T, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>), )
Apply callback f to all entries of the table.
§Note
In original libxml2, xmlHashScan/ScanFull allows to modify the table inner callback,
but it is obviously not safe.
Therefore, this method allow callback to modify the table.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("foo", 1u32);
table.add_entry2("hoge", Some("fuga"), 2);
table.add_entry3("foo", Some("bar"), Some("piyo"), 3);
let mut entries = vec![];
table.scan(|data, s1, s2, s3| entries.push(
(
*data,
s1.map_or("".to_owned(), |s| s.clone().into()),
s2.map_or("".to_owned(), |s| s.clone().into()),
s3.map_or("".to_owned(), |s| s.clone().into()),
)
));
entries.sort();
assert_eq!(
entries,
vec![
(1u32, "foo".to_owned(), "".to_owned(), "".to_owned()),
(2u32, "hoge".to_owned(), "fuga".to_owned(), "".to_owned()),
(3u32, "foo".to_owned(), "bar".to_owned(), "piyo".to_owned()),
],
)Sourcepub fn scan_mut(
&mut self,
f: impl FnMut(&mut T, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>),
)
pub fn scan_mut( &mut self, f: impl FnMut(&mut T, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>, Option<&Cow<'_, str>>), )
Apply callback f to all entries of the table.
§Note
In original libxml2, xmlHashScan/ScanFull allows to modify the table inner callback,
but it is obviously not safe.
Therefore, this method allow callback to modify the table.
§Examples
use exml::hash::XmlHashTable;
let mut table = XmlHashTable::new();
table.add_entry("foo", 1u32);
table.add_entry2("hoge", Some("fuga"), 2);
table.add_entry3("foo", Some("bar"), Some("piyo"), 3);
let mut entries = vec![];
table.scan_mut(|data, _, _, _| *data *= 2);
table.scan(|data, s1, s2, s3| entries.push(
(
*data,
s1.map_or("".to_owned(), |s| s.clone().into()),
s2.map_or("".to_owned(), |s| s.clone().into()),
s3.map_or("".to_owned(), |s| s.clone().into()),
)
));
entries.sort();
assert_eq!(
entries,
vec![
(2u32, "foo".to_owned(), "".to_owned(), "".to_owned()),
(4u32, "hoge".to_owned(), "fuga".to_owned(), "".to_owned()),
(6u32, "foo".to_owned(), "bar".to_owned(), "piyo".to_owned()),
],
)