kernel/processbuffer: accept arbitrary Ranges in ProcessSlice::get #4192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Overview
This commit changes the
{Readable,Writeable}ProcessSlice
types'get
method implementation to accept an arbitrary range type (usize
,Range
,RangeFrom
,RangeTo
), mirroring the semantics and implementation of the core library's implementation of this method on the slice primitive.This change makes it easier and more convenient to write panic-avoiding code when interacting with process memory.
It removes some redundancy in the
Index
trait implementations by making them generic over the newly introducedProcessSliceIndex
trait (which is necessary for the polymorphism of theget
method).While we could use the core library's
SliceIndex
trait, parameterized over our ownProcessSlice
types, this trait includes mandatory methods that are undesirable for the process buffer infrastructure, such as unchecked or mutable index operations. Furthermore, implementing it requires theslice_index_methods
nightly feature. Thus we vendor our own, small variant of this trait. The Rust standard library's implementation can be seen here: https://github.com/rust-lang/rust/blob/a1eceec00b2684f947481696ae2322e20d59db60/library/core/src/slice/index.rs#L200This change should be fully backwards compatible. It does, however, deprecate the now redundant
get_from
andget_to
methods. These were only used in one location across the entire upstream codebase.Testing Strategy
This pull request was tested by compiling.
TODO or Help Wanted
N/A
Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.