Lines Matching refs:slice

1290 mod slice;
3317 fn slice() {
6490 let slice: &[i32] = &[1, 2, 3];
6491 test_from_cow!(slice: &[i32]);
6630 let slice: &[isize] = &[4, 5];
6631 assert_eq!("[4, 5]", format!("{:?}", slice));
6720 let slice = &values[1..3];
6722 assert_eq!(slice, [2, 3]);
6729 let slice = &mut values[2..];
6730 assert!(slice == [3, 4, 5]);
6731 for p in slice {
6743 let slice = &mut values[..2];
6744 assert!(slice == [1, 2]);
6745 for p in slice {
7460 fn iter_equal<I: Iterator<Item = i32>>(it: I, slice: &[i32]) {
7462 assert_eq!(&v[..], slice);
7629 let borrowed: &[_] = &["borrowed", "(slice)"];
7639 let borrowed: &[_] = &["borrowed", "(slice)"];
7641 assert_eq!(Vec::from(Cow::Borrowed(borrowed)), vec!["borrowed", "(slice)"]);
8232 v.extend(&[1, 2]); // `slice::Iter` (with `T: Copy`) specialization
8883 mod slice;
9074 fn slice() {
9774 // small rotations in large slice, uses ptr::copy
9809 // small rotations in large slice, uses ptr::copy
10533 for slice in xs.split_mut(|x| *x == 0) {
10534 slice.reverse();
10539 for slice in xs.split_mut(|x| *x == 0).take(5) {
10540 slice.reverse();
10548 for slice in xs.split_mut(|x| *x == 0).rev().take(4) {
10549 slice.reverse();
10781 #[should_panic(expected = "source slice length (4) does not match destination slice length (5)")]
10789 #[should_panic(expected = "source slice length (4) does not match destination slice length (3)")]
11034 // in slice patterns `[$($pat), $(,)?]` .
11150 let slice = &[1, 1, 1, 3, 3, 2, 2, 2, 1, 0];
11152 let mut iter = slice.group_by(|a, b| a == b);
11160 let mut iter = slice.group_by(|a, b| a == b);
11168 let mut iter = slice.group_by(|a, b| a == b);
11179 let slice = &mut [1, 1, 1, 3, 3, 2, 2, 2, 1, 0];
11181 let mut iter = slice.group_by_mut(|a, b| a == b);
11189 let mut iter = slice.group_by_mut(|a, b| a == b);
11197 let mut iter = slice.group_by_mut(|a, b| a == b);
13931 // `slice::into_vec` function which is only available with cfg(test)
13932 // NB see the slice::hack module in slice.rs for more information
13942 $crate::slice::into_vec(box [$($x),*])
14432 use core::slice;
14569 pub fn from_box(slice: Box<[T], A>) -> Self {
14571 let (slice, alloc) = Box::into_raw_with_allocator(slice);
14572 RawVec::from_raw_parts_in(slice.as_mut_ptr(), slice.len(), alloc)
14597 let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
14598 Box::from_raw_in(slice, ptr::read(&me.alloc))
14985 //! Here we have declared a string literal, also known as a string slice.
15008 use crate::slice::{Concat, Join, SliceIndex};
15050 fn concat(slice: &Self) -> String {
15051 Join::join(slice, "")
15059 fn join(slice: &Self, sep: &str) -> String {
15060 unsafe { String::from_utf8_unchecked(join_generic_copy(slice, sep.as_bytes())) }
15111 fn join_generic_copy<B, T, S>(slice: &[S], sep: &[T]) -> Vec<T>
15118 let mut iter = slice.iter();
15120 // the first slice is the only one without a separator preceding it
15133 slice.iter().map(|s| s.borrow().as_ref().len()).try_fold(n, usize::checked_add)
15216 /// `replace` creates a new [`String`], and copies the data from this string slice into it.
15218 /// replaces them with the replacement string slice.
15254 /// `replacen` creates a new [`String`], and copies the data from this string slice into it.
15256 /// replaces them with the replacement string slice at most `count` times.
15291 /// Returns the lowercase equivalent of this string slice, as a new [`String`].
15376 /// Returns the uppercase equivalent of this string slice, as a new [`String`].
15444 let slice = Box::<[u8]>::from(self);
15445 unsafe { String::from_utf8_unchecked(slice.into_vec()) }
15534 /// Converts a boxed slice of bytes to a boxed string slice without checking
16223 use core::slice;
16321 /// slice [`&'a str`][`&str`] implements the trait `TraitExample`, and the function
16340 /// to explicitly extract the string slice containing the string. The second
16465 /// occur when converting a slice of [`u8`]s to a [`&str`]. In this sense, it's
16494 /// A possible error value when converting a `String` from a UTF-16 byte slice.
16588 // NB see the slice::hack module in slice.rs for more information
16603 /// If you are sure that the byte slice is valid UTF-8, and you don't want
16618 /// Returns [`Err`] if the slice is not UTF-8 with a description as to why the
16660 /// Converts a slice of bytes to a string, including invalid characters.
16662 /// Strings are made of bytes ([`u8`]), and a slice of bytes
16669 /// [byteslice]: prim@slice
16672 /// If you are sure that the byte slice is valid UTF-8, and you don't want
16679 /// This function returns a [`Cow<'a, str>`]. If our byte slice is invalid
16776 /// Decode a UTF-16–encoded slice `v` into a `String`, replacing
16942 /// Extracts a string slice containing the entire `String`.
16959 /// Converts a `String` into a mutable string slice.
16979 /// Appends a given string slice onto the end of this `String`.
17257 /// Returns a byte slice of this `String`'s contents.
17550 /// Inserts a string slice into this `String` at a byte position.
17748 let Range { start, end } = slice::range(range, ..self.len());
17755 // SAFETY: `slice::range` and `is_char_boundary` do the appropriate bounds checks.
17831 let slice = self.vec.into_boxed_slice();
17832 unsafe { from_boxed_utf8_unchecked(slice) }
17837 /// Returns a slice of [`u8`]s bytes that were attempted to convert to a `String`.
17882 /// occur when converting a slice of [`u8`]s to a [`&str`]. In this sense, it's
18541 /// Converts the given boxed `str` slice to a `String`.
18542 /// It is notable that the `str` slice is owned.
18562 /// Converts the given `String` to a boxed `str` slice that is owned.
18589 /// Converts a string slice into a Borrowed variant.
18746 /// Returns the remaining (sub)string of this iterator as a slice.
18943 /// let slice = [0, 1, 2];
18944 /// let mut input = Cow::from(&slice[..]);
18948 /// let slice = [-1, 0, 1];
18949 /// let mut input = Cow::from(&slice[..]);
18972 /// // Creates a container from borrowed values of a slice
18981 /// // Mutates the data from slice into owned vec and pushes a new value on top
19480 pub mod slice;
19759 use core::slice::from_raw_parts_mut;
20112 /// Constructs a new reference-counted slice with uninitialized contents.
20140 /// Constructs a new reference-counted slice with uninitialized contents, with the memory being
20789 /// Copy elements from slice into newly allocated Rc<\[T\]>
20817 let slice = from_raw_parts_mut(self.elems, self.n_elems);
20818 ptr::drop_in_place(slice);
20851 fn from_slice(slice: &[T]) -> Self;
21217 /// Allocate a reference-counted slice and fill it by cloning `v`'s items.
21235 /// Allocate a reference-counted string slice and copy `v` into it.
21253 /// Allocate a reference-counted string slice and copy `v` into it.
21289 /// Allocate a reference-counted slice and move `v`'s items into it.
21974 //! *[See also the slice primitive type](slice).*
21983 //! // coercing an array to a slice
21987 //! Slices are either mutable or shared. The shared slice type is `&[T]`,
21988 //! while the mutable slice type is `&mut [T]`, where `T` represents the element
21989 //! type. For example, you can mutate the block of memory that a mutable slice
22003 //! represents iteration over a slice.
22017 //! slice elements.
22026 //! The mutable slice yields mutable references to the elements:
22035 //! This iterator yields mutable references to the slice's elements, so while
22036 //! the element type of the slice is `i32`, the element type of the iterator is
22045 //! [`.iter`]: slice::iter
22046 //! [`.iter_mut`]: slice::iter_mut
22047 //! [`.split`]: slice::split
22048 //! [`.splitn`]: slice::splitn
22049 //! [`.chunks`]: slice::chunks
22050 //! [`.windows`]: slice::windows
22067 pub use core::slice::range;
22069 pub use core::slice::ArrayChunks;
22071 pub use core::slice::ArrayChunksMut;
22073 pub use core::slice::ArrayWindows;
22075 pub use core::slice::SliceIndex;
22077 pub use core::slice::{from_mut, from_ref};
22079 pub use core::slice::{from_raw_parts, from_raw_parts_mut};
22081 pub use core::slice::{Chunks, Windows};
22083 pub use core::slice::{ChunksExact, ChunksExactMut};
22085 pub use core::slice::{ChunksMut, Split, SplitMut};
22087 pub use core::slice::{GroupBy, GroupByMut};
22089 pub use core::slice::{Iter, IterMut};
22091 pub use core::slice::{RChunks, RChunksExact, RChunksExactMut, RChunksMut};
22093 pub use core::slice::{RSplit, RSplitMut};
22095 pub use core::slice::{RSplitN, RSplitNMut, SplitN, SplitNMut};
22098 // Basic slice extension methods
22113 // `core::slice::SliceExt` - we need to supply these functions for the
22198 /// Sorts the slice.
22204 /// See [`sort_unstable`](slice::sort_unstable).
22210 /// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
22233 /// Sorts the slice with a comparator function.
22237 /// The comparator function must define a total ordering for the elements in the slice. If
22245 /// `partial_cmp` as our sort function when we know the slice doesn't contain a `NaN`.
22255 /// See [`sort_unstable_by`](slice::sort_unstable_by).
22261 /// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
22287 /// Sorts the slice with a key extraction function.
22293 /// basic operations), [`sort_by_cached_key`](slice::sort_by_cached_key) is likely to be
22298 /// See [`sort_unstable_by_key`](slice::sort_unstable_by_key).
22304 /// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
22328 /// Sorts the slice with a key extraction function.
22336 /// basic operations), [`sort_by_key`](slice::sort_by_key) is likely to be
22348 /// length of the slice.
22369 ($t:ty, $slice:ident, $f:ident) => {{
22371 $slice.iter().map($f).enumerate().map(|(i, k)| (k, i as $t)).collect();
22373 // stable with respect to the original slice. We use `sort_unstable` here because
22376 for i in 0..$slice.len() {
22382 $slice.swap(i, index as usize);
22471 /// Creates a vector by repeating a slice `n` times.
22550 /// Flattens a slice of `T` into a single value `Self::Output`.
22566 /// Flattens a slice of `T` into a single value `Self::Output`, placing a
22584 /// Flattens a slice of `T` into a single value `Self::Output`, placing a
22607 /// Returns a vector containing a copy of this slice where each byte
22615 /// [`make_ascii_uppercase`]: slice::make_ascii_uppercase
22624 /// Returns a vector containing a copy of this slice where each byte
22632 /// [`make_ascii_lowercase`]: slice::make_ascii_lowercase
22646 /// Helper trait for [`[T]::concat`](slice::concat).
22654 /// --> src/liballoc/slice.rs:608:6
22681 /// Implementation of [`[T]::concat`](slice::concat)
22683 fn concat(slice: &Self) -> Self::Output;
22686 /// Helper trait for [`[T]::join`](slice::join)
22693 /// Implementation of [`[T]::join`](slice::join)
22695 fn join(slice: &Self, sep: Separator) -> Self::Output;
22702 fn concat(slice: &Self) -> Vec<T> {
22703 let size = slice.iter().map(|slice| slice.borrow().len()).sum();
22705 for v in slice {
22716 fn join(slice: &Self, sep: &T) -> Vec<T> {
22717 let mut iter = slice.iter();
22722 let size = slice.iter().map(|v| v.borrow().len()).sum::<usize>() + slice.len() - 1;
22738 fn join(slice: &Self, sep: &[T]) -> Vec<T> {
22739 let mut iter = slice.iter();
22745 slice.iter().map(|v| v.borrow().len()).sum::<usize>() + sep.len() * (slice.len() - 1);
22879 /// to hold a copy of the shorter slice. Also, `T` must not be a zero-sized type.
23291 use core::slice::from_raw_parts_mut;
23885 /// Constructs a new atomically reference-counted slice with uninitialized contents.
23913 /// Constructs a new atomically reference-counted slice with uninitialized contents, with the memory being
24439 /// Copy elements from slice into newly allocated Arc<\[T\]>
24469 let slice = from_raw_parts_mut(self.elems, self.n_elems);
24470 ptr::drop_in_place(slice);
24503 fn from_slice(slice: &[T]) -> Self;
25558 /// Allocate a reference-counted slice and fill it by cloning `v`'s items.
25630 /// Allocate a reference-counted slice and move `v`'s items into it.
37958 use core::slice::SliceIndex;
38371 // until the key slice reference is dropped, as we have unique access
38376 /// Borrows exclusive access to an element or slice of the node's value storage area.
38385 // until the value slice reference is dropped, as we have unique access
38392 /// Borrows exclusive access to an element or slice of the node's storage area for edge contents.
38401 // until the edge slice reference is dropped, as we have unique access
39564 /// Inserts a value into a slice of initialized elements followed by one uninitialized element.
39567 /// The slice has more than `idx` elements.
39568 unsafe fn slice_insert<T>(slice: &mut [MaybeUninit<T>], idx: usize, val: T) {
39570 let len = slice.len();
39572 let slice_ptr = slice.as_mut_ptr();
39580 /// Removes and returns a value from a slice of all initialized elements, leaving behind one
39584 /// The slice has more than `idx` elements.
39585 unsafe fn slice_remove<T>(slice: &mut [MaybeUninit<T>], idx: usize) -> T {
39587 let len = slice.len();
39589 let slice_ptr = slice.as_mut_ptr();
39596 /// Shifts the elements in a slice `distance` positions to the left.
39599 /// The slice has at least `distance` elements.
39600 unsafe fn slice_shl<T>(slice: &mut [MaybeUninit<T>], distance: usize) {
39602 let slice_ptr = slice.as_mut_ptr();
39603 ptr::copy(slice_ptr.add(distance), slice_ptr, slice.len() - distance);
39607 /// Shifts the elements in a slice `distance` positions to the right.
39610 /// The slice has at least `distance` elements.
39611 unsafe fn slice_shr<T>(slice: &mut [MaybeUninit<T>], distance: usize) {
39613 let slice_ptr = slice.as_mut_ptr();
39614 ptr::copy(slice_ptr, slice_ptr.add(distance), slice.len() - distance);
39618 /// Moves all values from a slice of initialized elements to a slice
40240 fn slice(self, from: usize, to: usize) -> Self;
40247 (buf.slice(tail, head), empty)
40257 fn slice(self, from: usize, to: usize) -> Self {
40266 fn slice(self, from: usize, to: usize) -> Self {
40275 fn slice(self, from: usize, to: usize) -> Self {
40298 /// PairSlices pairs up equal length slice parts of two deques
40375 use core::slice;
40428 /// in memory. If you want to access the elements as a single slice, such as for
40430 /// so that its elements do not wrap, and returns a mutable slice to the
40476 /// Runs the destructor for all items in the slice when it gets dropped (normally or
40525 /// Turn ptr into a slice
40528 unsafe { slice::from_raw_parts(self.ptr(), self.cap()) }
40531 /// Turn ptr into a mut slice
40534 unsafe { slice::from_raw_parts_mut(self.ptr(), self.cap()) }
41221 /// Runs the destructor for all items in the slice when it gets dropped (normally or
41235 // * Any slice passed to `drop_in_place` is valid; the second case has
41304 // `ring` we create is a dereferencable slice for lifetime '_.
41317 /// `VecDeque` will be in the first slice and the second slice will be empty.
41352 /// `VecDeque` will be in the first slice and the second slice will be empty.
41423 let Range { start, end } = slice::range(range, ..self.len());
41497 // `ring` we create is a dereferencable slice for lifetime '_.
42495 /// slice, which is then returned.
42498 /// inserted elements. As it returns a mutable slice, this can be used to
42503 /// `VecDeque` in a single slice.
42530 /// Getting immutable access to the contiguous slice.
42542 /// if let (slice, &[]) = buf.as_slices() {
42543 /// // we can now be sure that `slice` contains all elements of the deque,
42545 /// assert_eq!(buf.len(), slice.len());
42546 /// assert_eq!(slice, &[3, 2, 1] as &[_]);
42585 // to mean that we can just slice using `buf[tail..head]`.
42884 /// Looks up a series of four elements in a slice of pairs sorted by
43353 // single slice self.ring[self.tail..self.head]
43427 // single slice self.ring[self.tail..self.head]
44132 // Internal safety invariant: the entire slice is dereferencable.
44419 use crate::slice;
45249 /// Returns a slice of all values in the underlying vector, in arbitrary
45381 /// Hole represents a hole in a slice i.e., an index without valid value
45383 /// In drop, `Hole` will restore the slice by filling the hole
45394 /// Unsafe because pos must be within the data slice.
45398 // SAFE: pos should be inside the slice
45416 /// Unsafe because index must be within the data slice and not equal to pos.
45426 /// Unsafe because index must be within the data slice and not equal to pos.
45460 iter: slice::Iter<'a, T>,
45855 use core::slice::{self};
45889 /// Returns the remaining items of this iterator as a slice.
45902 unsafe { slice::from_raw_parts(self.ptr, self.len()) }
45905 /// Returns the remaining items of this iterator as a mutable slice.
46081 crate::slice::to_vec(self.as_slice(), self.alloc.clone()).into_iter()
46140 use core::slice::{self};
46213 impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
46217 fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) {
46218 let slice = iterator.as_slice();
46219 unsafe { self.append_elements(slice) };
46287 use core::slice::{self};
46313 pub(super) iter: slice::Iter<'a, T>,
46325 /// Returns the remaining items of this iterator as a slice.
46569 use core::slice::{self};
46589 /// | slice::Iter | | |
46649 impl<'a, T: 'a + Clone> SpecFromIter<&'a T, slice::Iter<'a, T>> for Vec<T> {
46651 fn from_iter(iterator: slice::Iter<'a, T>) -> Self {
46657 // `slice::to_vec` function which is only available with cfg(test)
46658 // NB see the slice::hack module in slice.rs for more information
46660 fn from_iter(iterator: slice::Iter<'a, T>) -> Self {
46661 crate::slice::to_vec(iterator.as_slice(), crate::alloc::Global)
46874 use core::slice::{self, SliceIndex};
47027 /// To get a [slice][prim@slice], use [`&`]. Example:
47030 /// fn read_slice(slice: &[usize]) {
47093 /// you would see if you coerced it to a slice), followed by [`capacity`]` -
47150 /// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
47179 /// [owned slice]: Box
47749 /// Converts the vector into [`Box<[T]>`][owned slice].
47753 /// [owned slice]: Box
47760 /// let slice = v.into_boxed_slice();
47770 /// let slice = vec.into_boxed_slice();
47771 /// assert_eq!(slice.into_vec().capacity(), 3);
47830 // * the slice passed to `drop_in_place` is valid; the `len > self.len`
47831 // case avoids creating an invalid slice, and
47849 /// Extracts a slice containing the entire vector.
47866 /// Extracts a mutable slice of the entire vector.
47892 /// derived from it. If you need to mutate the contents of the slice, use [`as_mut_ptr`].
47911 // We shadow the slice method of the same name to avoid going through
47947 // We shadow the slice method of the same name to avoid going through
48317 /// from their order in the slice, so if `same_bucket(a, b)` returns `true`, `a` is removed.
48368 /* Pointer to first item in vec[write..write+items_left] slice */
48370 /* Pointer to first item in vec[read..] slice */
48390 * doing slice partition_dedup + truncate */
48551 let Range { start, end } = slice::range(range, ..len);
48558 let range_slice = slice::from_raw_parts_mut(self.as_mut_ptr().add(start), end - start);
48746 /// Returns the remaining spare capacity of the vector as a slice of
48749 /// The returned slice can be used to fill the vector with data (e.g. by
48783 slice::from_raw_parts_mut(
48790 /// Returns vector content as a slice of `T`, along with the remaining spare
48791 /// capacity of the vector as a slice of `MaybeUninit<T>`.
48793 /// The returned spare capacity slice can be used to fill the vector with data
48864 let initialized = slice::from_raw_parts_mut(ptr, self.len);
48865 let spare = slice::from_raw_parts_mut(spare_ptr, spare_len);
48906 /// Clones and appends all elements in a slice to the `Vec`.
48908 /// Iterates over the slice `other`, clones each element, and then appends
48951 let range = slice::range(src, ..self.len());
48955 // - `slice::range` guarantees that the given range is valid for indexing self
49105 // - Both pointers are created from unique slice references (`&mut [_]`)
49131 unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
49138 unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
49152 // `slice::to_vec` function which is only available with cfg(test)
49153 // NB see the slice::hack module in slice.rs for more information
49157 crate::slice::to_vec(&**self, alloc)
49261 type IntoIter = slice::Iter<'a, T>;
49263 fn into_iter(self) -> slice::Iter<'a, T> {
49271 type IntoIter = slice::IterMut<'a, T>;
49273 fn into_iter(self) -> slice::IterMut<'a, T> {
49426 /// This implementation is specialized for slice iterators, where it uses [`copy_from_slice`] to
49427 /// append the entire slice at once.
49429 /// [`copy_from_slice`]: slice::copy_from_slice
49473 // use a raw slice to refer to the elements of the vector as weakest necessary type;
49539 crate::slice::to_vec(s, Global)
49558 crate::slice::to_vec(s, Global)
49577 crate::slice::into_vec(box s)
49586 /// Convert a clone-on-write slice into a vector.
49589 /// If `s` is borrowing a slice, a new `Vec<T>` will be allocated and
49609 /// Convert a boxed slice into a vector by transferring ownership of
49627 /// Convert a vector into a boxed slice.
49736 use core::slice::{self};
49803 let v = slice::from_raw_parts_mut(self.vec.as_mut_ptr(), self.old_len);
49957 use core::slice::{self};
50059 slice::from_raw_parts_mut(vec.as_mut_ptr().add(range_start), range_end - range_start)
50089 use core::slice::{self};
50091 // A helper struct for in-place iteration that drops the destination slice of iteration,
50092 // i.e. the head. The source slice (the tail) is dropped by IntoIter.
50108 ptr::drop_in_place(slice::from_raw_parts_mut(self.inner, self.len()));
50700 /// Constructs a new boxed slice with uninitialized contents.
50725 /// Constructs a new boxed slice with uninitialized contents, with the memory
50750 /// Constructs a new boxed slice with uninitialized contents in the provided allocator.
50778 /// Constructs a new boxed slice with uninitialized contents in the provided allocator,
51392 /// and performs a copy of `slice`.
51397 /// let slice: &[u8] = &[104, 101, 108, 108, 111];
51398 /// let boxed_slice: Box<[u8]> = Box::from(slice);
51402 fn from(slice: &[T]) -> Box<[T]> {
51403 let len = slice.len();
51406 ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len);
51407 buf.into_box(slice.len()).assume_init()
51417 Cow::Borrowed(slice) => Box::from(slice),
51418 Cow::Owned(slice) => Box::from(slice),
51465 /// let slice: &[u8] = &[104, 101, 108, 108, 111];
51466 /// let boxed_slice = Box::from(slice);
52058 let slice: &[f64] = &[-1.0, 0.0, 1.0, f64::INFINITY];
52059 let boxed: Box<[f64]> = Box::from(slice);
52060 assert_eq!(&*boxed, slice)
52065 let slice: &[i64] = &[i64::MIN, -2, -1, 0, 1, 2, i64::MAX];
52066 let boxed: Box<[i64]> = Box::from(slice);
52067 assert_eq!(&*boxed, slice)