For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
ContiguousSlice
struct ContiguousSlice
Represents a slice expression without a stride.
This type is used to support different behavior for strided vs unstrided slicing.
Fields
- start (
Optional[Int]): The starting index of the slice. - end (
Optional[Int]): The end index of the slice.
Implemented traits
AnyType,
Copyable,
Deinitable,
ImplicitlyCopyable,
Movable,
Writable
Methods
__init__
def __init__(out self, start: Optional[Int], end: Optional[Int], stride: NoneType, __slice_literal__: NoneType = None)
Constructs a contiguous slice with the given start and end.
Args:
- start (
Optional[Int]): The starting index of the slice. - end (
Optional[Int]): The end index of the slice. - stride (
NoneType): Always none. Disambiguates from slices with a stride. - slice_literal (
NoneType): Enables slice literal syntax.
write_to
def write_to(self, mut writer: T)
Writes the contiguous slice's string representation to a writer.
Args:
- writer (
T): The object to write to.
write_repr_to
def write_repr_to(self, mut writer: T)
Writes the contiguous slice's debug representation to a writer.
Args:
- writer (
T): The object to write to.
indices
def indices(self, length: Int) -> Tuple[Int, Int]
Resolves the slice's start and end against the length of a container.
A negative bound counts back from length, a None bound becomes
the start or the end, and an out-of-bounds bound is clamped to the
range [0, length].
Args:
- length (
Int): The length of the container the slice applies to.
Returns:
Tuple[Int, Int]: A tuple of the resolved start and end.