mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
Implement Deref for BoundedSlice (#11660)
* Impl Deref for BoundedSlice Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update primitives/runtime/src/bounded/bounded_vec.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d4b89c6f5d
commit
525fc8ebc3
@@ -223,6 +223,15 @@ impl<'a, T, S> Clone for BoundedSlice<'a, T, S> {
|
||||
// Since a reference `&T` is always `Copy`, so is `BoundedSlice<'a, T, S>`.
|
||||
impl<'a, T, S> Copy for BoundedSlice<'a, T, S> {}
|
||||
|
||||
// will allow for all immutable operations of `[T]` on `BoundedSlice<T>`.
|
||||
impl<'a, T, S> Deref for BoundedSlice<'a, T, S> {
|
||||
type Target = [T];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, S> sp_std::iter::IntoIterator for BoundedSlice<'a, T, S> {
|
||||
type Item = &'a T;
|
||||
type IntoIter = sp_std::slice::Iter<'a, T>;
|
||||
@@ -647,7 +656,7 @@ impl<T, S> AsMut<[T]> for BoundedVec<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
// will allow for immutable all operations of `Vec<T>` on `BoundedVec<T>`.
|
||||
// will allow for all immutable operations of `Vec<T>` on `BoundedVec<T>`.
|
||||
impl<T, S> Deref for BoundedVec<T, S> {
|
||||
type Target = Vec<T>;
|
||||
|
||||
@@ -970,7 +979,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref_coercion_works() {
|
||||
fn deref_vec_coercion_works() {
|
||||
let bounded: BoundedVec<u32, ConstU32<7>> = bounded_vec![1, 2, 3];
|
||||
// these methods come from deref-ed vec.
|
||||
assert_eq!(bounded.len(), 3);
|
||||
@@ -978,6 +987,15 @@ pub mod test {
|
||||
assert!(!bounded.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref_slice_coercion_works() {
|
||||
let bounded = BoundedSlice::<u32, ConstU32<7>>::try_from(&[1, 2, 3][..]).unwrap();
|
||||
// these methods come from deref-ed slice.
|
||||
assert_eq!(bounded.len(), 3);
|
||||
assert!(bounded.iter().next().is_some());
|
||||
assert!(!bounded.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_mutate_works() {
|
||||
let bounded: BoundedVec<u32, ConstU32<7>> = bounded_vec![1, 2, 3, 4, 5, 6];
|
||||
|
||||
Reference in New Issue
Block a user