Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
ink
Commits
a791a322
Commit
a791a322
authored
Jan 23, 2019
by
Hero Bird
Browse files
[pdsl_core] Add IndexMut<u32> impl for storage::Vec
parent
0c6c0963
Changes
2
Hide whitespace changes
Inline
Side-by-side
pdsl_core/src/storage/collections/vec/tests.rs
View file @
a791a322
...
...
@@ -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
(||
{
...
...
pdsl_core/src/storage/collections/vec/vec.rs
View file @
a791a322
...
...
@@ -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"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment