Skip to main content

VacantEntry

Struct VacantEntry 

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

Source

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

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

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> 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> 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<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.