Skip to main content

Entry

Enum Entry 

Source
pub enum Entry<'a, 'k> {
    Occupied(OccupiedEntry<'a, 'k>),
    Vacant(VacantEntry<'a, 'k>),
}
Expand description

A view into a single entry in a ZendHashTable, which may either be vacant or occupied.

This enum is constructed from the entry method on ZendHashTable.

Variants§

§

Occupied(OccupiedEntry<'a, 'k>)

An occupied entry.

§

Vacant(VacantEntry<'a, 'k>)

A vacant entry.

Implementations§

Source§

impl<'a, 'k> Entry<'a, 'k>

Source

pub fn or_insert<V: IntoZval>(self, default: V) -> Result<&'a mut Zval>

Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.

§Parameters
  • default - The default value to insert if the entry is vacant.
§Returns

A result containing a mutable reference to the 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();
ht.entry("key").or_insert("default value");
assert_eq!(ht.get("key").and_then(|v| v.str()), Some("default value"));
Source

pub fn or_insert_with<V: IntoZval, F: FnOnce() -> V>( self, default: F, ) -> Result<&'a mut Zval>

Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value in the entry.

§Parameters
  • default - A function that returns the default value to insert.
§Returns

A result containing a mutable reference to the 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();
ht.entry("key").or_insert_with(|| "computed value");
Source

pub fn or_insert_with_key<V: IntoZval, F: FnOnce(&ArrayKey<'k>) -> V>( self, default: F, ) -> Result<&'a mut Zval>

Ensures a value is in the entry by inserting the result of the default function if empty. The function receives a reference to the key.

§Parameters
  • default - A function that takes the key and returns the default value.
§Returns

A result containing a mutable reference to the 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();
ht.entry("key").or_insert_with_key(|k| format!("value for {}", k));
Source

pub fn key(&self) -> &ArrayKey<'k>

Returns a reference to this entry’s key.

§Example
use ext_php_rs::types::{ZendHashTable, ArrayKey};

let mut ht = ZendHashTable::new();
assert_eq!(ht.entry("key").key(), &ArrayKey::Str("key"));
Source

pub fn and_modify<F: FnOnce(&mut Zval)>(self, f: F) -> Self

Provides in-place mutable access to an occupied entry before any potential inserts into the map.

§Parameters
  • f - A function that modifies the value in place.
§Returns

The entry, allowing for method chaining.

§Example
use ext_php_rs::types::ZendHashTable;

let mut ht = ZendHashTable::new();
ht.insert("counter", 0i64);

ht.entry("counter")
    .and_modify(|v| {
        if let Some(n) = v.long() {
            v.set_long(n + 1);
        }
    })
    .or_insert(0i64);
Source§

impl<'a, 'k> Entry<'a, 'k>
where 'k: 'a,

Source

pub fn or_default(self) -> Result<&'a mut Zval>

Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.

This is a convenience method that uses Default::default() as the default value.

§Returns

A result containing a mutable reference to the value, or an error if the insertion failed.

§Errors

Returns an error if the key contains a null byte (for string keys).

§Example
use ext_php_rs::types::ZendHashTable;

let mut ht = ZendHashTable::new();
// Inserts a null Zval if the key doesn't exist
ht.entry("key").or_default();

Auto Trait Implementations§

§

impl<'a, 'k> Freeze for Entry<'a, 'k>

§

impl<'a, 'k> RefUnwindSafe for Entry<'a, 'k>

§

impl<'a, 'k> !Send for Entry<'a, 'k>

§

impl<'a, 'k> !Sync for Entry<'a, 'k>

§

impl<'a, 'k> Unpin for Entry<'a, 'k>

§

impl<'a, 'k> !UnwindSafe for Entry<'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.