module std::iosource
Console and file input/output.
This module is the standard library's FFI barrier (LANGUAGE_SPEC.md section 6.3): programs call these safe wrappers and never touch the system underneath. The externs are the compiler's al_sys_* functions, one C file a platform (alloyc/src/support/system.c); streams cross the boundary as opaque i64 handles (a C stream natively; the interpreter implements the same names over the host filesystem, with handles 1 and 2 as the standard streams).
standard_streamprintprint_lineprint_errorprint_error_lineFileFile::openFile::createFile::extenddisposereadwritesyncsizeread_inputread_filewrite_file
fn standard_streamsource
exp fn standard_stream(index: u32) -> i64
The C stream for standard input (0), output (1) or error (2). A lang item (LANGUAGE_SPEC.md section 6.1a): the compiler supplies it for each target, so this body never runs.
fn printsource
exp fn print(text: &[u8])
Writes the text to standard output.
fn print_linesource
exp fn print_line(text: &[u8])
Writes the text and a newline to standard output, as one line no other task's output splits.
fn print_errorsource
exp fn print_error(text: &[u8])
Writes the text to standard error.
fn print_error_linesource
exp fn print_error_line(text: &[u8])
Writes the text and a newline to standard error, as one line no other task's output splits.
type Filesource
exp type File : Disposable = struct
An open file, closed by disposing it (section 5.2). Reads and writes go through the C library's buffering, so small ones are cheap.
Functions
exp fn File::open(path: &[u8]) -> Option<File>exp fn File::create(path: &[u8]) -> Option<File>exp fn File::extend(path: &[u8]) -> Option<File>exp fn dispose(self file: &var File)exp fn read(self file: &var File, buffer: &var [u8]) -> u64exp fn write(self file: &var File, bytes: &[u8]) -> boolexp fn sync(self file: &var File) -> boolexp fn size(self file: &var File) -> u64
fn File::opensource
exp fn File::open(path: &[u8]) -> Option<File>
Opens an existing file for reading, or None when it cannot be.
fn File::createsource
exp fn File::create(path: &[u8]) -> Option<File>
Creates a file for writing, emptying it if it exists, or None when it
cannot be.
fn File::extendsource
exp fn File::extend(path: &[u8]) -> Option<File>
Opens a file for writing at its end, creating it if missing, or None
when it cannot be.
fn disposesource
exp fn dispose(self file: &var File)
Closes the file.
fn readsource
exp fn read(self file: &var File, buffer: &var [u8]) -> u64
Reads into the buffer and returns how many bytes it filled: fewer than its length only at the end of the file or on an error.
fn writesource
exp fn write(self file: &var File, bytes: &[u8]) -> bool
Writes all the bytes; false when they could not all be written.
fn syncsource
exp fn sync(self file: &var File) -> bool
Writes what was written through to the disk, so it survives the machine stopping; false when it cannot be.
fn sizesource
exp fn size(self file: &var File) -> u64
The file's size in bytes, leaving the position at the start.
fn read_inputsource
exp fn read_input(buffer: &var [u8]) -> u64
Reads from standard input into the buffer and returns how many bytes it filled: fewer than its length only at the end of the input.
fn read_filesource
exp fn read_file(path: &[u8]) -> Option<*[u8]>
Reads a whole file into an owned byte array, or None when the file
cannot be opened.
fn write_filesource
exp fn write_file(path: &[u8], contents: &[u8]) -> bool
Writes the bytes to the file, replacing any previous contents. False when the file cannot be created or written.