diff options
author | Alice Ryhl <aliceryhl@google.com> | 2025-05-02 13:19:31 +0000 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2025-05-07 18:39:01 +0200 |
commit | 9def0d0a2a1c62d7970f4ce5ad5557968c98f637 (patch) | |
tree | 3438b34f02cf9471b8baca0cd6a26ee3d01507d3 /scripts/generate_rust_analyzer.py | |
parent | f2b4dd7093438e4884cb01a783212abfbc9cc40b (diff) |
rust: alloc: add Vec::push_within_capacity
This introduces a new method called `push_within_capacity` for appending
to a vector without attempting to allocate if the capacity is full. Rust
Binder will use this in various places to safely push to a vector while
holding a spinlock.
The implementation is moved to a push_within_capacity_unchecked method.
This is preferred over having push() call push_within_capacity()
followed by an unwrap_unchecked() for simpler unsafe.
Panics in the kernel are best avoided when possible, so an error is
returned if the vector does not have sufficient capacity. An error type
is used rather than just returning Result<(),T> to make it more
convenient for callers (i.e. they can use ? or unwrap).
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-3-06d20ad9366f@google.com
[ Remove public visibility from `Vec::push_within_capacity_unchecked()`.
- Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'scripts/generate_rust_analyzer.py')
0 files changed, 0 insertions, 0 deletions