struct
OwnedKwargsDict
Container used to pass owned variadic keyword arguments to functions.
This type mimics the interface of a dictionary with String
keys, and
should be usable more-or-less like a dictionary. Notably, however, this type
should not be instantiated directly by users.
Parameters
- V (
CollectionElement
): The value type of the dictionary. Currently must be CollectionElement.
Aliases
key_type = String
:
Implemented traits
AnyType
,
CollectionElement
,
Copyable
,
Movable
,
Sized
Methods
__init__
__init__(inout self: Self, /)
Initialize an empty keyword dictionary.
__copyinit__
__copyinit__(inout self: Self, /, existing: Self)
Copy an existing keyword dictionary.
Args:
- existing (
Self
): The existing keyword dictionary.
__moveinit__
__moveinit__(inout self: Self, /, owned existing: Self)
Move data of an existing keyword dictionary into a new one.
Args:
- existing (
Self
): The existing keyword dictionary.
__getitem__
__getitem__(self: Self, key: String) -> V
Retrieve a value out of the keyword dictionary.
Args:
- key (
String
): The key to retrieve.
Returns:
The value associated with the key, if it's present.
Raises:
"KeyError" if the key isn't present.
__setitem__
__setitem__(inout self: Self, key: String, value: V)
Set a value in the keyword dictionary by key.
Args:
- key (
String
): The key to associate with the specified value. - value (
V
): The data to store in the dictionary.
__contains__
__contains__(self: Self, key: String) -> Bool
Check if a given key is in the keyword dictionary or not.
Args:
- key (
String
): The key to check.
Returns:
True if there key exists in the keyword dictionary, False otherwise.
__len__
__len__(self: Self) -> Int
The number of elements currenly stored in the keyword dictionary.
find
find(self: Self, key: String) -> Optional[V]
Find a value in the keyword dictionary by key.
Args:
- key (
String
): The key to search for in the dictionary.
Returns:
An optional value containing a copy of the value if it was present, otherwise an empty Optional.
pop
pop(inout self: Self, key: String, owned default: Optional[V] = #kgen.none) -> V
Remove a value from the keyword dictionary by key.
Args:
- key (
String
): The key to remove from the dictionary. - default (
Optional[V]
): Optionally provide a default value to return if the key was not found instead of raising.
Returns:
The value associated with the key, if it was in the dictionary. If it wasn't, return the provided default value instead.
Raises:
"KeyError" if the key was not present in the dictionary and no default value was provided.
__iter__
__iter__[mutability: i1, self_life: lifetime<*(0,0)>](self: !lit.ref<_stdlib::_collections::_dict::_OwnedKwargsDict<:trait<_stdlib::_builtin::_value::_CollectionElement> V>, mut=mutability, self_life>) -> _DictKeyIter[String, V, $0, $1, true]
Iterate over the keyword dict's keys as immutable references.
Parameters:
- mutability (
i1
): Whether the dict is mutable. - self_life (
lifetime<*(0,0)>
): The dict's lifetime.
Returns:
An iterator of immutable references to the dictionary keys.
keys
keys[mutability: i1, self_life: lifetime<*(0,0)>](self: !lit.ref<_stdlib::_collections::_dict::_OwnedKwargsDict<:trait<_stdlib::_builtin::_value::_CollectionElement> V>, mut=mutability, self_life>) -> _DictKeyIter[String, V, $0, $1, true]
Iterate over the keyword dict's keys as immutable references.
Parameters:
- mutability (
i1
): Whether the dict is mutable. - self_life (
lifetime<*(0,0)>
): The dict's lifetime.
Returns:
An iterator of immutable references to the dictionary keys.
values
values[mutability: i1, self_life: lifetime<*(0,0)>](self: !lit.ref<_stdlib::_collections::_dict::_OwnedKwargsDict<:trait<_stdlib::_builtin::_value::_CollectionElement> V>, mut=mutability, self_life>) -> _DictValueIter[String, V, $0, $1]
Iterate over the keyword dict's values as references.
Parameters:
- mutability (
i1
): Whether the dict is mutable. - self_life (
lifetime<*(0,0)>
): The dict's lifetime.
Returns:
An iterator of references to the dictionary values.
items
items[mutability: i1, self_life: lifetime<*(0,0)>](self: !lit.ref<_stdlib::_collections::_dict::_OwnedKwargsDict<:trait<_stdlib::_builtin::_value::_CollectionElement> V>, mut=mutability, self_life>) -> _DictEntryIter[String, V, $0, $1, true]
Iterate over the keyword dictionary's entries as immutable references.
These can't yet be unpacked like Python dict items, but you can access the key and value as attributes ie.
for e in dict.items():
print(e[].key, e[].value)
Parameters:
- mutability (
i1
): Whether the dict is mutable. - self_life (
lifetime<*(0,0)>
): The dict's lifetime.
Returns:
An iterator of immutable references to the dictionary entries.