Struct valord_map::RefMut

source ·
pub struct RefMut<'v, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,
{ /* private fields */ }

Implementations§

source§

impl<'v, T, K, V> RefMut<'v, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,

source

pub fn get_mut_with_key(&mut self) -> (&K, &mut V)

Examples found in repository?
examples/people_ord_by_age.rs (line 118)
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
fn main() {
    let mut peoples = ValordMap::new();
    peoples.insert(
        1,
        People {
            age: 18,
            name: "qians1".to_string(),
        },
    );
    peoples.insert(
        2,
        People {
            age: 19,
            name: "qians2".to_string(),
        },
    );
    peoples.insert(
        3,
        People {
            age: 20,
            name: "qians3".to_string(),
        },
    );
    peoples.insert(
        4,
        People {
            age: 21,
            name: "qians4".to_string(),
        },
    );
    peoples.insert(
        5,
        People {
            age: 22,
            name: "qians5".to_string(),
        },
    );

    let youngest = peoples.first();
    assert_eq!(youngest.len(), 1);
    assert_eq!(
        youngest[0],
        (
            &1,
            &People {
                age: 18,
                name: "qians1".to_string(),
            }
        )
    );

    let oldest = peoples.last();
    assert_eq!(oldest.len(), 1);
    assert_eq!(
        oldest[0],
        (
            &5,
            &People {
                age: 22,
                name: "qians5".to_string(),
            }
        )
    );

    peoples
        .iter_mut()
        .for_each(|mut people_ref_mut| people_ref_mut.age += 1);

    let youngest = peoples.first();
    assert_eq!(youngest.len(), 1);
    assert_eq!(
        youngest[0],
        (
            &1,
            &People {
                age: 19,
                name: "qians1".to_string(),
            }
        )
    );

    let oldest = peoples.last();
    assert_eq!(oldest.len(), 1);
    assert_eq!(
        oldest[0],
        (
            &5,
            &People {
                age: 23,
                name: "qians5".to_string(),
            }
        )
    );

    let range: Vec<_> = peoples.range(22..).collect();
    assert_eq!(range.len(), 2);
    println!("range: {range:?}");

    let range: Vec<_> = peoples
        .range_mut(22..)
        .map(|mut rm_p| {
            let (k, v) = rm_p.get_mut_with_key();
            v.age = 30;
            (*k, v.name.clone(), v.age)
        })
        .collect();

    println!("range mut: {range:?}");

    let oldest = peoples.last();
    assert_eq!(oldest.len(), 2);
    assert_eq!(oldest[0].1.age, 30,);
    assert_eq!(oldest[1].1.age, 30);
    println!("peoples: {:?}", peoples.iter().collect::<Vec<_>>());
}

Trait Implementations§

source§

impl<'a, T, K, V> Deref for RefMut<'a, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,

§

type Target = V

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'a, T, K, V> DerefMut for RefMut<'a, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,

source§

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

Mutably dereferences the value.
source§

impl<'a, T, K, V> Drop for RefMut<'a, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'v, T, K, V> Freeze for RefMut<'v, T, K, V>

§

impl<'v, T, K, V> RefUnwindSafe for RefMut<'v, T, K, V>

§

impl<'v, T, K, V> Send for RefMut<'v, T, K, V>
where T: Send, K: Send, V: Send,

§

impl<'v, T, K, V> Sync for RefMut<'v, T, K, V>
where T: Sync, K: Sync, V: Sync,

§

impl<'v, T, K, V> Unpin for RefMut<'v, T, K, V>

§

impl<'v, T, K, V> !UnwindSafe for RefMut<'v, T, K, 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, 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.