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[UInt8])
Implemented traits
Section titled “Implemented traits”AnyType, ImplicitlyDestructible, Movable, WriterBackend
Methods
Section titled “Methods”__init__
Section titled “__init__”fn __init__(out self)Initialize MemoryWriter with an empty buffer.
Args:
- self (
Self)
Returns:
Self
fn __init__(out self, *, deinit take: Self)Move constructor.
Args:
- take (
Self) - self (
Self)
Returns:
Self
write_from_buffer
Section titled “write_from_buffer”fn write_from_buffer(mut self, mut buf: Span[UInt8, MutExternalOrigin], amt: Int, pos: Int = 0) -> UInt64Write bytes from buffer to memory.
Args:
- self (
Self) - buf (
Span[UInt8, MutExternalOrigin]) - amt (
Int) - pos (
Int)
Returns:
UInt64
Raises:
get_data
Section titled “get_data”fn get_data(self) -> List[UInt8]Get a copy of the written data.
Args:
- self (
Self)
Returns:
List[UInt8]
get_data_ref
Section titled “get_data_ref”fn get_data_ref(self) -> Span[UInt8, origin_of(self.data)]Get owned reference to the written data.
Args:
- self (
Self)
Returns:
Span[UInt8, origin_of(self.data)]
fn clear(mut self)Clear the buffer.
Args:
- self (
Self)