pub struct VacantEntry<'a, 'k> { /* private fields */ }Expand description
A view into a vacant entry in a ZendHashTable.
It is part of the Entry enum.
Implementations§
Source§impl<'a, 'k> VacantEntry<'a, 'k>
impl<'a, 'k> VacantEntry<'a, 'k>
Sourcepub fn key(&self) -> &ArrayKey<'k>
pub fn key(&self) -> &ArrayKey<'k>
Gets a reference to the key that would be used when inserting a value
through the VacantEntry.
§Example
use ext_php_rs::types::{ZendHashTable, ArrayKey};
let mut ht = ZendHashTable::new();
if let ext_php_rs::types::array::Entry::Vacant(entry) = ht.entry("key") {
assert_eq!(entry.key(), &ArrayKey::Str("key"));
}Sourcepub fn into_key(self) -> ArrayKey<'k>
pub fn into_key(self) -> ArrayKey<'k>
Take ownership of the key.
§Example
use ext_php_rs::types::{ZendHashTable, ArrayKey};
let mut ht = ZendHashTable::new();
if let ext_php_rs::types::array::Entry::Vacant(entry) = ht.entry("key") {
let key = entry.into_key();
assert_eq!(key, ArrayKey::Str("key"));
}Sourcepub fn insert<V: IntoZval>(self, value: V) -> Result<&'a mut Zval>
pub fn insert<V: IntoZval>(self, value: V) -> Result<&'a mut Zval>
Sets the value of the entry with the VacantEntry’s key, and returns
a mutable reference to it.
§Parameters
value- The value to insert.
§Returns
A result containing a mutable reference to the inserted value, or an error if the insertion failed.
§Errors
Returns an error if the value conversion to Zval fails or if
the key contains a null byte (for string keys).
§Example
use ext_php_rs::types::ZendHashTable;
let mut ht = ZendHashTable::new();
if let ext_php_rs::types::array::Entry::Vacant(entry) = ht.entry("key") {
entry.insert("value");
}
assert_eq!(ht.get("key").and_then(|v| v.str()), Some("value"));Auto Trait Implementations§
impl<'a, 'k> Freeze for VacantEntry<'a, 'k>
impl<'a, 'k> RefUnwindSafe for VacantEntry<'a, 'k>
impl<'a, 'k> !Send for VacantEntry<'a, 'k>
impl<'a, 'k> !Sync for VacantEntry<'a, 'k>
impl<'a, 'k> Unpin for VacantEntry<'a, 'k>
impl<'a, 'k> !UnwindSafe for VacantEntry<'a, 'k>
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