XmlHashTableRef

Struct XmlHashTableRef 

Source
pub struct XmlHashTableRef<'a, T>(/* private fields */);

Implementations§

Source§

impl<'a, T> XmlHashTableRef<'a, T>

Source

pub fn new() -> Option<Self>

Source

pub fn with_capacity(size: usize) -> Option<Self>

Source

pub fn from_table(table: XmlHashTable<'a, T>) -> Option<Self>

Source

pub fn as_ptr<'b>(self) -> *mut XmlHashTable<'b, T>
where 'a: 'b,

Source

pub fn into_inner(self) -> XmlHashTable<'a, T>

Source

pub fn free(self)

Methods from Deref<Target = XmlHashTable<'a, T>>§

Source

pub fn clear(&mut self)

Source

pub fn clear_with(&mut self, deallocator: impl Fn(T, Option<Cow<'_, str>>))

Source

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);
Source

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);
Source

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);
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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));
Source

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.

Source

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.

Source

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())
    ]
);
Source

pub fn len(&self) -> usize

Return the number of entries owned by the table.

Source

pub fn is_empty(&self) -> bool

Check if the table has no entries.

Source

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.

Source

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()),
    ],
)
Source

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()),
    ],
)
Source

pub fn drain(&'a mut self) -> Drain<'a, T>

Trait Implementations§

Source§

impl<T> Clone for XmlHashTableRef<'_, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Deref for XmlHashTableRef<'a, T>

Source§

type Target = XmlHashTable<'a, T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for XmlHashTableRef<'_, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Copy for XmlHashTableRef<'_, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for XmlHashTableRef<'a, T>

§

impl<'a, T> RefUnwindSafe for XmlHashTableRef<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for XmlHashTableRef<'a, T>

§

impl<'a, T> !Sync for XmlHashTableRef<'a, T>

§

impl<'a, T> Unpin for XmlHashTableRef<'a, T>

§

impl<'a, T> UnwindSafe for XmlHashTableRef<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V