Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
03ab76e9
Commit
03ab76e9
authored
2 years ago
by
Xiliang Chen
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add sort & try_append to bounded_vec (#11196)
parent
641a43a0
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/frame/support/src/storage/bounded_vec.rs
+21
-0
21 additions, 0 deletions
substrate/frame/support/src/storage/bounded_vec.rs
with
21 additions
and
0 deletions
substrate/frame/support/src/storage/bounded_vec.rs
+
21
−
0
View file @
03ab76e9
...
@@ -129,6 +129,16 @@ impl<T, S> BoundedVec<T, S> {
...
@@ -129,6 +129,16 @@ impl<T, S> BoundedVec<T, S> {
self
.0
.sort_by
(
compare
)
self
.0
.sort_by
(
compare
)
}
}
/// Exactly the same semantics as [`slice::sort`].
///
/// This is safe since sorting cannot change the number of elements in the vector.
pub
fn
sort
(
&
mut
self
)
where
T
:
sp_std
::
cmp
::
Ord
,
{
self
.0
.sort
()
}
/// Exactly the same semantics as `Vec::remove`.
/// Exactly the same semantics as `Vec::remove`.
///
///
/// # Panics
/// # Panics
...
@@ -374,6 +384,17 @@ impl<T, S: Get<u32>> BoundedVec<T, S> {
...
@@ -374,6 +384,17 @@ impl<T, S: Get<u32>> BoundedVec<T, S> {
}
}
}
}
/// Exactly the same semantics as [`Vec::append`], but returns an error and does nothing if the
/// length of the outcome is larger than the bound.
pub
fn
try_append
(
&
mut
self
,
other
:
&
mut
Vec
<
T
>
)
->
Result
<
(),
()
>
{
if
other
.len
()
.saturating_add
(
self
.len
())
<=
Self
::
bound
()
{
self
.0
.append
(
other
);
Ok
(())
}
else
{
Err
(())
}
}
/// Consumes self and mutates self via the given `mutate` function.
/// Consumes self and mutates self via the given `mutate` function.
///
///
/// If the outcome of mutation is within bounds, `Some(Self)` is returned. Else, `None` is
/// If the outcome of mutation is within bounds, `Some(Self)` is returned. Else, `None` is
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment