pub struct RawEntry<'v, T, K, V>{ /* private fields */ }Implementations§
Source§impl<'v, T, K, V> RawEntry<'v, T, K, V>
impl<'v, T, K, V> RawEntry<'v, T, K, V>
Sourcepub fn get_mut_with_key(&mut self) -> (&K, &mut V)
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§
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>
impl<'v, T, K, V> Sync for RawEntry<'v, T, K, V>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more