Files
std/io/writable.sakura
T
2026-10-29 09:21:10 -05:00

40 lines
1.5 KiB
Plaintext

#! @file writable.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains the writable trait, which anything bytes are written to implements: a
#! file, the console, a writer, or a string.
import system;
module std::io;
#! Anything bytes are written to.
#!
#! A write writes all of what it is given, or gives why it could not, so a
#! caller never writes the rest again. Something that holds bytes back before
#! passing them on is also `flushable`, and whoever made it flushes it: code
#! given a `&mut writable` only writes.
#!
#! A reference that writes, `&mut` one, is writable where what it refers to is,
#! so a generic given `&mut s` writes `s` without owning it.
pub trait writable {
#! Writes all of some bytes.
#! @param this The stream to write.
#! @param data The bytes to write.
#! @returns Why they could not all be written, where they could not.
def write(&mut this, data: span<u8>): result<void, io_error>;
}
#! Writes bytes after the last, as a stream is written, so a string is given
#! where anything `writable` is wanted, as a test gives one to collect what is
#! written.
#! @param this The string to write to.
#! @param data The bytes to write.
#! @returns Nothing, since a string always takes them: an allocator that gives
#! no more memory stops the program.
pub def string::write(&mut this, data: span<u8>): result<void, io_error> {
this.append(data);
return;
}