Struct RawEntry

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

Implementations§

Source§

impl<'v, T, K, V> RawEntry<'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)
17fn main() {
18    let mut peoples = ValordMap::new();
19    peoples.insert(
20        1,
21        People {
22            age: 18,
23            name: "qians1".to_string(),
24        },
25    );
26    peoples.insert(
27        2,
28        People {
29            age: 19,
30            name: "qians2".to_string(),
31        },
32    );
33    peoples.insert(
34        3,
35        People {
36            age: 20,
37            name: "qians3".to_string(),
38        },
39    );
40    peoples.insert(
41        4,
42        People {
43            age: 21,
44            name: "qians4".to_string(),
45        },
46    );
47    peoples.insert(
48        5,
49        People {
50            age: 22,
51            name: "qians5".to_string(),
52        },
53    );
54
55    let youngest = peoples.first();
56    assert_eq!(youngest.len(), 1);
57    assert_eq!(
58        youngest[0],
59        (
60            &1,
61            &People {
62                age: 18,
63                name: "qians1".to_string(),
64            }
65        )
66    );
67
68    let oldest = peoples.last();
69    assert_eq!(oldest.len(), 1);
70    assert_eq!(
71        oldest[0],
72        (
73            &5,
74            &People {
75                age: 22,
76                name: "qians5".to_string(),
77            }
78        )
79    );
80
81    peoples
82        .iter_mut()
83        .for_each(|mut people_ref_mut| people_ref_mut.age += 1);
84
85    let youngest = peoples.first();
86    assert_eq!(youngest.len(), 1);
87    assert_eq!(
88        youngest[0],
89        (
90            &1,
91            &People {
92                age: 19,
93                name: "qians1".to_string(),
94            }
95        )
96    );
97
98    let oldest = peoples.last();
99    assert_eq!(oldest.len(), 1);
100    assert_eq!(
101        oldest[0],
102        (
103            &5,
104            &People {
105                age: 23,
106                name: "qians5".to_string(),
107            }
108        )
109    );
110
111    let range: Vec<_> = peoples.range(22..).collect();
112    assert_eq!(range.len(), 2);
113    println!("range: {range:?}");
114
115    let range: Vec<_> = peoples
116        .range_mut(22..)
117        .map(|mut rm_p| {
118            let (k, v) = rm_p.get_mut_with_key();
119            v.age = 30;
120            (*k, v.name.clone(), v.age)
121        })
122        .collect();
123
124    println!("range mut: {range:?}");
125
126    let oldest = peoples.last();
127    assert_eq!(oldest.len(), 2);
128    assert_eq!(oldest[0].1.age, 30,);
129    assert_eq!(oldest[1].1.age, 30);
130    println!("peoples: {:?}", peoples.iter().collect::<Vec<_>>());
131}

Trait Implementations§

Source§

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

Source§

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 RawEntry<'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 RawEntry<'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 RawEntry<'v, T, K, V>

§

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

§

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

§

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

§

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

§

impl<'v, T, K, V> !UnwindSafe for RawEntry<'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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.