Trait otter_api_tests::IndexMut 1.0.0[−][src]
#[lang = "index_mut"] pub trait IndexMut<Idx>: Index<Idx> where
Idx: ?Sized, { pub fn index_mut(&mut self, index: Idx) -> &mut Self::Output; }
Used for indexing operations (container[index]
) in mutable contexts.
container[index]
is actually syntactic sugar for
*container.index_mut(index)
, but only when used as a mutable value. If
an immutable value is requested, the Index
trait is used instead. This
allows nice things such as v[index] = value
.
Examples
A very simple implementation of a Balance
struct that has two sides, where
each can be indexed mutably and immutably.
use std::ops::{Index, IndexMut}; #[derive(Debug)] enum Side { Left, Right, } #[derive(Debug, PartialEq)] enum Weight { Kilogram(f32), Pound(f32), } struct Balance { pub left: Weight, pub right: Weight, } impl Index<Side> for Balance { type Output = Weight; fn index(&self, index: Side) -> &Self::Output { println!("Accessing {:?}-side of balance immutably", index); match index { Side::Left => &self.left, Side::Right => &self.right, } } } impl IndexMut<Side> for Balance { fn index_mut(&mut self, index: Side) -> &mut Self::Output { println!("Accessing {:?}-side of balance mutably", index); match index { Side::Left => &mut self.left, Side::Right => &mut self.right, } } } let mut balance = Balance { right: Weight::Kilogram(2.5), left: Weight::Pound(1.5), }; // In this case, `balance[Side::Right]` is sugar for // `*balance.index(Side::Right)`, since we are only *reading* // `balance[Side::Right]`, not writing it. assert_eq!(balance[Side::Right], Weight::Kilogram(2.5)); // However, in this case `balance[Side::Left]` is sugar for // `*balance.index_mut(Side::Left)`, since we are writing // `balance[Side::Left]`. balance[Side::Left] = Weight::Kilogram(3.0);
Required methods
pub fn index_mut(&mut self, index: Idx) -> &mut Self::Output
[src]
Performs the mutable indexing (container[index]
) operation.
Implementations on Foreign Types
impl IndexMut<RangeFull> for OsString
[src]
impl<T, I> IndexMut<I> for [T] where
I: SliceIndex<[T]>,
[src]
I: SliceIndex<[T]>,
impl<I> IndexMut<I> for str where
I: SliceIndex<str>,
[src]
I: SliceIndex<str>,
pub fn index_mut(&mut self, index: I) -> &mut <I as SliceIndex<str>>::Output
[src]
impl<T, I, const N: usize> IndexMut<I> for [T; N] where
[T]: IndexMut<I>,
[src]
[T]: IndexMut<I>,
impl IndexMut<RangeInclusive<usize>> for String
[src]
pub fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut str
[src]
impl IndexMut<RangeToInclusive<usize>> for String
[src]
pub fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut str
[src]
impl IndexMut<RangeFull> for String
[src]
impl IndexMut<RangeTo<usize>> for String
[src]
impl IndexMut<Range<usize>> for String
[src]
impl<T, I, A> IndexMut<I> for Vec<T, A> where
A: Allocator,
I: SliceIndex<[T]>,
[src]
A: Allocator,
I: SliceIndex<[T]>,
impl IndexMut<RangeFrom<usize>> for String
[src]
impl<T> IndexMut<User> for [T; 2]
[src]
pub fn index_mut(&mut self, index: User) -> &mut TⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<T> IndexMut<usize> for Slab<T>
[src]
pub fn index_mut(&mut self, key: usize) -> &mut TⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<A, I> IndexMut<I> for SmallVec<A> where
A: Array,
I: SliceIndex<[<A as Array>::Item]>,
A: Array,
I: SliceIndex<[<A as Array>::Item]>,
pub fn index_mut(
&mut self,
index: I
) -> &mut <I as SliceIndex<[<A as Array>::Item]>>::Output
&mut self,
index: I
) -> &mut <I as SliceIndex<[<A as Array>::Item]>>::Output
impl<A, I> IndexMut<I> for ArrayVec<A> where
A: Array,
I: SliceIndex<[<A as Array>::Item]>,
A: Array,
I: SliceIndex<[<A as Array>::Item]>,
impl<A, I> IndexMut<I> for TinyVec<A> where
A: Array,
I: SliceIndex<[<A as Array>::Item]>,
A: Array,
I: SliceIndex<[<A as Array>::Item]>,
impl<'s, T, I> IndexMut<I> for SliceVec<'s, T> where
I: SliceIndex<[T]>,
I: SliceIndex<[T]>,
impl<V> IndexMut<usize> for VecMap<V>
pub fn index_mut(&mut self, i: usize) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<'a, V> IndexMut<&'a usize> for VecMap<V>
pub fn index_mut(&mut self, i: &usize) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Implementors
impl<'a, Q> IndexMut<&'a Q> for otter_api_tests::imports::toml::value::Map<String, Value> where
Q: Ord + Eq + Hash + ?Sized,
String: Borrow<Q>,
[src]
Q: Ord + Eq + Hash + ?Sized,
String: Borrow<Q>,
Mutably access an element of this map. Panics if the given key is not present in the map.
impl<'a, Q> IndexMut<&'a Q> for otter_api_tests::serde_json::Map<String, Value> where
Q: Ord + Eq + Hash + ?Sized,
String: Borrow<Q>,
[src]
Q: Ord + Eq + Hash + ?Sized,
String: Borrow<Q>,
Mutably access an element of this map. Panics if the given key is not present in the map.
map["key"] = json!("value");
impl<A> IndexMut<usize> for VecDeque<A>
[src]
pub fn index_mut(&mut self, index: usize) -> &mut AⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<I> IndexMut<I> for otter_api_tests::imports::toml::Value where
I: Index,
[src]
I: Index,
impl<I> IndexMut<I> for otter_api_tests::serde_json::Value where
I: Index,
[src]
I: Index,
pub fn index_mut(&mut self, index: I) -> &mut Value
[src]
Write into a serde_json::Value
using the syntax value[0] = ...
or
value["k"] = ...
.
If the index is a number, the value must be an array of length bigger than the index. Indexing into a value that is not an array or an array that is too small will panic.
If the index is a string, the value must be an object or null which is treated like an empty object. If the key is not already present in the object, it will be inserted with a value of null. Indexing into a value that is neither an object nor null will panic.
Examples
let mut data = json!({ "x": 0 }); // replace an existing key data["x"] = json!(1); // insert a new key data["y"] = json!([false, false, false]); // replace an array value data["y"][0] = json!(true); // inserted a deeply nested key data["a"]["b"]["c"]["d"] = json!(true); println!("{}", data);
impl<I, R, T> IndexMut<R> for IndexSlice<I, [T]> where
R: IdxSliceIndex<I, T>,
I: Idx,
R: IdxSliceIndex<I, T>,
I: Idx,
pub fn index_mut(&mut self, index: R) -> &mut <R as IdxSliceIndex<I, T>>::Output
impl<K, V> IndexMut<K> for HopSlotMap<K, V> where
K: Key,
[src]
K: Key,
pub fn index_mut(&mut self, key: K) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<K, V> IndexMut<K> for SecondaryMap<K, V> where
K: Key,
[src]
K: Key,
pub fn index_mut(&mut self, key: K) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<K, V> IndexMut<K> for SlotMap<K, V> where
K: Key,
[src]
K: Key,
pub fn index_mut(&mut self, key: K) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<K, V> IndexMut<K> for DenseSlotMap<K, V> where
K: Key,
[src]
K: Key,
pub fn index_mut(&mut self, key: K) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<K, V> IndexMut<K> for EnumMap<K, V> where
K: Enum<V>,
K: Enum<V>,
pub fn index_mut(&mut self, key: K) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<K, V, S> IndexMut<K> for SparseSecondaryMap<K, V, S> where
S: BuildHasher,
K: Key,
[src]
S: BuildHasher,
K: Key,
pub fn index_mut(&mut self, key: K) -> &mut VⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
impl<T, I> IndexMut<I> for Deque<T, I> where
I: Offset,
I: Offset,
pub fn index_mut(&mut self, i: I) -> &mut TⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;