BString
Mojo struct 🡭
BString
Section titled “BString”@memory_onlystruct BStringByteString is a mutable sequence of bytes. it does not ensure any encoding of the bytes.
Fields
Section titled “Fields”- size (
UInt32) - cap (
UInt32) - ptr (
UnsafePointer[UInt8, MutExternalOrigin])
Implemented traits
Section titled “Implemented traits”AnyType, Copyable, Equatable, ImplicitlyDestructible, Movable, Sized, Writable
Methods
Section titled “Methods”__init__
Section titled “__init__”def __init__(out self, capacity: UInt = 0)Args:
- capacity (
UInt) - self (
Self)
Returns:
Self
def __init__(out self, s: String)Args:
- s (
String) - self (
Self)
Returns:
Self
def __init__(out self, s: Span[UInt8, s.origin])Args:
- s (
Span) - self (
Self)
Returns:
Self
def __init__(out self, s: StringSlice[s.origin])Args:
- s (
StringSlice) - self (
Self)
Returns:
Self
__getitem__
Section titled “__getitem__”def __getitem__[I: Indexer](self, idx: I) -> UInt8Parameters:
- I (
Indexer)
Args:
- self (
Self) - idx (
I)
Returns:
UInt8
def __getitem__(ref self, slice: Slice) -> Span[UInt8, origin_of(self)]Args:
- self (
Self) - slice (
Slice)
Returns:
Span
__setitem__
Section titled “__setitem__”def __setitem__[I: Indexer](mut self, idx: I, val: UInt8)Parameters:
- I (
Indexer)
Args:
- self (
Self) - idx (
I) - val (
UInt8)
__eq__
Section titled “__eq__”def __eq__(self, other: Self) -> BoolArgs:
- self (
Self) - other (
Self)
Returns:
Bool
__ne__
Section titled “__ne__”def __ne__(self, other: Self) -> BoolCompare two ASCIIStrings for inequality.
Args:
- self (
Self) - other (
Self)
Returns:
Bool
__len__
Section titled “__len__”def __len__(self) -> IntArgs:
- self (
Self)
Returns:
Int
def addr[I: Indexer](mut self, i: I) -> UnsafePointer[UInt8, MutExternalOrigin]Parameters:
- I (
Indexer)
Args:
- self (
Self) - i (
I)
Returns:
UnsafePointer
def clear(mut self)Args:
- self (
Self)
reserve
Section titled “reserve”def reserve(mut self, cap: UInt32)Args:
- self (
Self) - cap (
UInt32)
resize
Section titled “resize”def resize(mut self, size: UInt32)Args:
- self (
Self) - size (
UInt32)
as_span
Section titled “as_span”def as_span(ref self) -> Span[UInt8, origin_of(self)]Args:
- self (
Self)
Returns:
Span
to_string
Section titled “to_string”def to_string(self) -> StringArgs:
- self (
Self)
Returns:
String
as_string_slice
Section titled “as_string_slice”def as_string_slice(ref self) -> StringSlice[origin_of(self)]Return StringSlice view of BString bytes.
Args:
- self (
Self)
Returns:
StringSlice
write_to
Section titled “write_to”def write_to[w: Writer](self, mut writer: w)Parameters:
- w (
Writer)
Args:
- self (
Self) - writer (
w)
extend
Section titled “extend”def extend(mut self, src: Span[UInt8, src.origin])Args:
- self (
Self) - src (
Span)
def extend(mut self, src: List[UInt8])Args:
- self (
Self) - src (
List)
def extend(mut self, src: Self)Args:
- self (
Self) - src (
Self)