Commit a791a322 authored by Hero Bird's avatar Hero Bird
Browse files

[pdsl_core] Add IndexMut<u32> impl for storage::Vec

parent 0c6c0963
......@@ -131,6 +131,24 @@ fn index() {
})
}
#[test]
fn index_mut() {
run_test(|| {
let mut vec = {
let mut vec = new_empty_vec();
vec.push(String::from("Hello"));
vec.push(String::from(", "));
vec.push(String::from("World!"));
assert_eq!(vec.len(), 3);
vec
};
vec[2] = String::from("Substrate!");
assert_eq!(vec[0], "Hello");
assert_eq!(vec[1], ", ");
assert_eq!(vec[2], "Substrate!");
})
}
#[test]
fn index_comp() {
run_test(|| {
......
......@@ -338,7 +338,7 @@ where
impl<T> core::ops::Index<u32> for Vec<T>
where
T: parity_codec::Codec
T: parity_codec::Codec,
{
type Output = T;
......@@ -351,3 +351,17 @@ where
)
}
}
impl<T> core::ops::IndexMut<u32> for Vec<T>
where
T: parity_codec::Codec,
{
fn index_mut(&mut self, index: u32) -> &mut Self::Output {
self
.get_mut(index)
.expect(
"[pdsl_core::Vec::index] Error: \
expected `index` to be within bounds"
)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment