IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
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, ImplicitlyCopyable, ImplicitlyDestructible, Movable, Writable

Methods

__init__

__init__(out self, start: Optional[Int], end: Optional[Int], stride: NoneType, __slice_literal__: NoneType = None)

Construct slice given the start and end values.

Args:

  • start (Optional[Int]): The start value.
  • end (Optional[Int]): The end value.
  • stride (NoneType): Always none. Disambiguates from slices with a stride.
  • slice_literal (NoneType): Enables slice literal syntax.

write_to

write_to(self, mut writer: T)

Write ContiguousSlice string representation to a Writer.

Args:

  • writer (T): The object to write to.

write_repr_to

write_repr_to(self, mut writer: T)

Write ContiguousSlice debug representation to a Writer.

Args:

  • writer (T): The object to write to.

indices

indices(self, length: Int) -> Tuple[Int, Int]

Returns a tuple of 2 integers representing the start, and end of the slice if applied to a container of the given length.

Args:

  • length (Int): The length of the target container.

Returns:

Tuple[Int, Int]: A tuple containing two integers for start and end.