Skip to content

BString

Mojo struct 🡭

@memory_only
struct BString

ByteString is a mutable sequence of bytes. it does not ensure any encoding of the bytes.

  • size (UInt32)
  • cap (UInt32)
  • ptr (UnsafePointer[UInt8, MutExternalOrigin])

AnyType, Copyable, Equatable, ImplicitlyDestructible, Movable, Sized, Writable

fn __init__(out self, capacity: UInt = UInt(0))

Args:

  • capacity (UInt)
  • self (Self)

Returns:

Self

fn __init__(out self, s: String)

Args:

  • s (String)
  • self (Self)

Returns:

Self

fn __init__(out self, s: Span[UInt8])

Args:

  • s (Span[UInt8])
  • self (Self)

Returns:

Self

fn __init__(out self, s: StringSlice)

Args:

  • s (StringSlice)
  • self (Self)

Returns:

Self

fn __getitem__[I: Indexer](self, idx: I) -> UInt8

Parameters:

  • I (Indexer)

Args:

  • self (Self)
  • idx (I)

Returns:

UInt8

fn __getitem__(ref self, slice: Slice) -> Span[UInt8, origin_of(self)]

Args:

  • self (Self)
  • slice (Slice)

Returns:

Span[UInt8, origin_of(self)]

fn __setitem__[I: Indexer](mut self, idx: I, val: UInt8)

Parameters:

  • I (Indexer)

Args:

  • self (Self)
  • idx (I)
  • val (UInt8)
fn __eq__(self, other: Self) -> Bool

Args:

  • self (Self)
  • other (Self)

Returns:

Bool

fn __ne__(self, other: Self) -> Bool

Compare two ASCIIStrings for inequality.

Args:

  • self (Self)
  • other (Self)

Returns:

Bool

fn __len__(self) -> Int

Args:

  • self (Self)

Returns:

Int

fn addr[I: Indexer](mut self, i: I) -> UnsafePointer[UInt8, MutExternalOrigin]

Parameters:

  • I (Indexer)

Args:

  • self (Self)
  • i (I)

Returns:

UnsafePointer[UInt8, MutExternalOrigin]

fn clear(mut self)

Args:

  • self (Self)
fn reserve(mut self, cap: UInt32)

Args:

  • self (Self)
  • cap (UInt32)
fn resize(mut self, size: UInt32)

Args:

  • self (Self)
  • size (UInt32)
fn as_span(ref self) -> Span[UInt8, origin_of(self)]

Args:

  • self (Self)

Returns:

Span[UInt8, origin_of(self)]

fn to_string(self) -> String

Args:

  • self (Self)

Returns:

String

fn as_string_slice(ref self) -> StringSlice[origin_of(self)]

Return StringSlice view of BString bytes.

Args:

  • self (Self)

Returns:

StringSlice[origin_of(self)]

fn write_to[w: Writer](self, mut writer: w)

Parameters:

  • w (Writer)

Args:

  • self (Self)
  • writer (w)
fn extend(mut self, src: Span[UInt8])

Args:

  • self (Self)
  • src (Span[UInt8])
fn extend(mut self, src: List[UInt8])

Args:

  • self (Self)
  • src (List[UInt8])
fn extend(mut self, src: Self)

Args:

  • self (Self)
  • src (Self)