MemoryWriter
Mojo struct 🡭
MemoryWriter
Section titled “MemoryWriter”@memory_onlystruct MemoryWriterWriter that writes to an in-memory buffer.
Useful for testing, string building, or when you need to collect output in memory before writing to a file.
Fields
Section titled “Fields”- data (
List[Byte])
Implemented traits
Section titled “Implemented traits”AnyType, ImplicitlyDestructible, Movable, WriterBackend
Methods
Section titled “Methods”__init__
Section titled “__init__”def __init__(out self)Initialize MemoryWriter with an empty buffer.
Args:
- self (
Self)
Returns:
Self
def __init__(out self, *, deinit take: Self)Move constructor.
Args:
- take (
Self) - self (
Self)
Returns:
Self
write_from_buffer
Section titled “write_from_buffer”def write_from_buffer(mut self, mut buf: Span[Byte, MutExternalOrigin], amt: Int, pos: Int = 0) -> UInt64Write bytes from buffer to memory.
Args:
- self (
Self) - buf (
Span) - amt (
Int) - pos (
Int)
Returns:
UInt64
Raises:
get_data
Section titled “get_data”def get_data(self) -> List[Byte]Get a copy of the written data.
Args:
- self (
Self)
Returns:
List
get_data_ref
Section titled “get_data_ref”def get_data_ref(self) -> Span[Byte, origin_of(self.data)]Get owned reference to the written data.
Args:
- self (
Self)
Returns:
Span
def clear(mut self)Clear the buffer.
Args:
- self (
Self)