ReadOnlySpan¶
No import is needed.
Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.
ReadOnlySpan¶
ReadOnlySpan<T> - a Span<T> without the writers: no indexer setter, set, fill, or copy_from. Take one when a function borrows a run of elements and promises not to change them. The same ref struct escape rules as Span<T> apply (see docs/language/types/spans.md).
constructor¶
A view of array[offset .. offset + length). Traps unless that range lies inside array.
of¶
Creates a read-only character view of src without copying its contents.
of¶
A read-only span over the whole of array.
length¶
Number of elements this span covers.
is_empty¶
True when this span covers no elements.
this¶
The element at index (relative to this span). Traps if out of range.
this¶
Accesses the element at index; an out-of-range index panics.
slice¶
Returns a view of elements from start (inclusive) to end (exclusive) that shares this span's storage. Panics unless 0 <= start <= end <= length.
slice¶
Returns a view of UTF-16 units from start (inclusive) to end (exclusive), including views over a string. Panics unless 0 <= start <= end <= length.
slice¶
Returns a view from start to the end of this span. Panics unless 0 <= start <= length.
index_of¶
Index of the first element equal to value (by value equality), or None.
index_of¶
Returns the first matching index, or None when no match exists.
contains¶
True when some element equals value.
sequence_equal¶
True when other has the same length and pairwise-equal elements. Element-wise == even for unmanaged T: a bitwise compare would disagree with == on floating-point NaN and -0.0.
copy_to¶
Copies every element into dst starting at index 0. Traps if dst is shorter. Overlap within one array is handled like Span<T>.copy_from.
copy_to¶
Array-backed unmanaged elements use one bulk copy; strings widen UTF-16 units.
to_array¶
Copies every element into a fresh, independently-owned array.
to_array¶
Copies the elements into a new array.