core::collections::slice
이 페이지의 내용
- Structs
- Implementations
impl List1
API 참조는 영어로만 있습니다. 표준 라이브러리 소스의 영어 문서 주석에서 만듭니다.
Slice<T>, a zero-copy view;
element i is buf[start + i * stride], and the view keeps
its buffer alive.
xs[a:b] is xs.slice(a..b) and xs[a:b:k] is
xs.slice(index::slice_range(a, b, k, len)).step(k), with Python's
semantics (bounds clamp, xs[::-1] reverses). A view of a List sees
later element writes but not a regrowth, which moves the list to a new
buffer; a view of an array or StrBuf views a copy.
Structs
SliceSource
pub struct Slice<T>A zero-copy view of a buffer: element i is
buf[start + i * stride]. A view of a List sees later element writes
but not a regrowth; a view of an array or StrBuf views a copy.
The number of elements.
truewhen the slice has no element.Element
i, ornoneout of bounds.The first element;
nonewhen empty.The last element;
nonewhen empty.Every
kth element (k!= 0), back to front whenk< 0.The elements front to back.
Views of
[0, mid)and[mid, len); panics ifmidis past the length.Views of
sizeconsecutive elements, sliding by one (size> 0); nothing when the view is shorter thansize.Views of
sizeelements in order, the last one shorter (size> 0).(buffer, start, len)of the viewed elements as one contiguous run, for runtime calls on a buffer region. A strided view is copied first, so writes through its run do not reach the view.The view
raw_partstakes apart:lenelements ofbuffromstart.A new list holding the viewed elements.
The first index whose element fails
pred, which must hold for a prefix and fail for the rest; O(log n).The index of the first element equal to
xin an ascending view, ornone; O(log n).truewhen an element equalsx.
SliceIterSource
pub struct SliceIter<T>s.iter() / for x in s, in view order.
Trait implementations 4
impl<T> Debug for SliceIter<T>impl<T> Iterator for SliceIter<T>impl<T> DoubleEndedIterator for SliceIter<T>impl<T> ExactSizeIterator for SliceIter<T>
WindowsSource
pub struct Windows<T>s.windows(size): each window is a view of s, no copy.
Trait implementations 3
impl<T> Debug for Windows<T>impl<T> Iterator for Windows<T>impl<T> ExactSizeIterator for Windows<T>
ChunksSource
pub struct Chunks<T>s.chunks(size): each chunk is a view of s, no copy.
Trait implementations 3
impl<T> Debug for Chunks<T>impl<T> Iterator for Chunks<T>impl<T> ExactSizeIterator for Chunks<T>
SliceMutSource
pub struct SliceMut<T>A writable view of a list's elements, like Rust's
&mut [T]: s[i] = x writes the list. A List<T> passed where a
SliceMut<T> is expected views the whole list, and xs[a:b] there
views xs[a:b]. Element i is buf[start + i].
A view lives as long as nothing resizes its list. Resizing it
(push, insert, clear, ...) while a view is still used later is a
compile error where the compiler can see both; elsewhere the view's
methods (and each step of a walk over it) notice the list's new
version and panic. Element reads and writes (s[i], get) check
nothing, so a loop over a view runs as fast as one over a list: on a
stale view they reach the storage the view was made of, which no
other thread can reach (freezing a list that had views copies it).
The number of elements.
truewhen there are no elements.Element
i, ornoneout of bounds.The first element;
nonewhen empty.The last element;
nonewhen empty.Overwrite every element with
x.Exchange elements
iandj; panics out of bounds.The elements in reverse order, in place.
Overwrite the elements with those of
src, which must be as long (s.copy_from_slice(ys[:])); panics otherwise.Views of
[0, mid)and[mid, len), both writable; panics ifmidis past the length.Writable views of
sizeelements in order, the last one shorter (size> 0). They do not overlap, sopar::for_eachmay give each to its own worker.The same elements as a read-only
Slice.
Sourcepub const fn iter(§self) -> SliceMutIter<T> The elements in order.
A new list holding the viewed elements.
Ascending by
key(x), stable;keyruns twice per comparison.Stable merge sort by
cmp: O(n log n), n extra slots.(buffer, start, len)of the viewed elements, for runtime calls that fill a buffer region.Ascending, stable.
truewhen an element equalsx.
Trait implementations 8
impl<T> !Sync for SliceMut<T>impl<T> IntoIterator for SliceMut<T>impl<T> Index<usize> for SliceMut<T>impl<T> IndexSet<usize, T> for SliceMut<T>impl<T> Sliceable<Range<usize>> for SliceMut<T>impl<T: PartialEq> PartialEq for SliceMut<T>impl<T: Debug> Debug for SliceMut<T>impl<T> Transfer for SliceMut<T>
ChunksMutSource
pub struct ChunksMut<T>xs.chunks_mut(size): each chunk is a writable view of its own part
of the list, no copy.
Trait implementations 3
impl<T> Debug for ChunksMut<T>impl<T> Iterator for ChunksMut<T>impl<T> ExactSizeIterator for ChunksMut<T>
SliceMutIterSource
pub struct SliceMutIter<T>s.iter() / for x in s: checks the view on every step.
Trait implementations 4
impl<T> Debug for SliceMutIter<T>impl<T> Iterator for SliceMutIter<T>impl<T> DoubleEndedIterator for SliceMutIter<T>impl<T> ExactSizeIterator for SliceMutIter<T>
Implementations
impl List
self[:].find(needle).