Struct starlark::values::dict::DictMut

source ·
pub struct DictMut<'v> { /* private fields */ }
Expand description

Mutably borrowed Dict.

Implementations§

source§

impl<'v> DictMut<'v>

source

pub fn from_value(x: Value<'v>) -> Result<DictMut<'_>>

Downcast the value to a mutable dict reference.

Methods from Deref<Target = Dict<'v>>§

source

pub const TYPE: &'static str = "dict"

source

pub fn len(&self) -> usize

Number of elements in the dict.

source

pub fn is_empty(&self) -> bool

Is the dict empty?

source

pub fn iter<'a>( &'a self ) -> impl ExactSizeIterator<Item = (Value<'v>, Value<'v>)> + 'a

Iterate through the key/value pairs in the dictionary.

source

pub fn iter_hashed<'a>( &'a self ) -> impl Iterator<Item = (Hashed<Value<'v>>, Value<'v>)> + 'a
where 'v: 'a,

Iterate through the key/value pairs in the dictionary, but retaining the hash of the keys.

source

pub fn keys<'a>(&'a self) -> impl Iterator<Item = Value<'v>> + 'a

Iterator over keys.

source

pub fn values<'a>(&'a self) -> impl Iterator<Item = Value<'v>> + 'a

Iterator over keys.

source

pub fn get(&self, key: Value<'v>) -> Result<Option<Value<'v>>>

Get the value associated with a particular key. Will be Err if the key is not hashable, and otherwise Some if the key exists in the dictionary and None otherwise.

source

pub fn get_hashed(&self, key: Hashed<Value<'v>>) -> Option<Value<'v>>

Lookup the value by the given prehashed key.

source

pub fn get_str(&self, key: &str) -> Option<Value<'v>>

Get the value associated with a particular string. Equivalent to allocating the string on the heap, turning it into a value, and looking up using that.

source

pub fn get_str_hashed(&self, key: Hashed<&str>) -> Option<Value<'v>>

Like Dict::get_str, but where you already have the hash.

source

pub fn reserve(&mut self, additional: usize)

Reserve capacity to insert additional elements without reallocating.

source

pub fn insert_hashed(&mut self, key: Hashed<Value<'v>>, value: Value<'v>)

Insert a key/value pair into the dictionary.

source

pub fn remove_hashed(&mut self, key: Hashed<Value<'v>>) -> Option<Value<'v>>

Remove given key from the dictionary.

source

pub fn clear(&mut self)

Remove all elements from the dictionary.

Trait Implementations§

source§

impl<'v> Deref for DictMut<'v>

§

type Target = Dict<'v>

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'v> DerefMut for DictMut<'v>

source§

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

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'v> !RefUnwindSafe for DictMut<'v>

§

impl<'v> !Send for DictMut<'v>

§

impl<'v> !Sync for DictMut<'v>

§

impl<'v> Unpin for DictMut<'v>

§

impl<'v> !UnwindSafe for DictMut<'v>

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> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

source§

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

§

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

§

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.