Skip to main content

Host

Trait Host 

Source
pub trait Host {
Show 43 methods // Required method fn print(&mut self, text: &str); // Provided methods fn rich_display(&self) -> Option<RichDisplay> { ... } fn print_markup(&mut self, markup: &str) { ... } fn print_input(&mut self, text: &str) { ... } fn random_bytes(&mut self, buffer: &mut [u8]) { ... } fn read_file(&mut self, name: &str) -> Result<Vec<u8>, FileError> { ... } fn write_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError> { ... } fn file_info(&mut self, name: &str, follow_links: bool) -> Option<FileInfo> { ... } fn delete_file(&mut self, name: &str) -> Result<(), FileError> { ... } fn rename_file(&mut self, from: &str, to: &str) -> Result<(), FileError> { ... } fn create_dir(&mut self, name: &str, parents: bool) -> Result<(), FileError> { ... } fn remove_dir( &mut self, name: &str, contents: bool, ) -> Result<(), FileError> { ... } fn list_dir(&mut self, name: &str) -> Option<Vec<String>> { ... } fn absolute_path(&mut self, name: &str) -> Option<String> { ... } fn root_dirs(&mut self) -> Vec<String> { ... } fn sandbox(&mut self, name: &str) -> Sandbox { ... } fn temp_file_name(&mut self) -> Option<String> { ... } fn special_file(&mut self, id: i32) -> Option<String> { ... } fn append_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError> { ... } fn read_line(&mut self) -> Input { ... } fn read_key(&mut self) -> Input { ... } fn choose_file( &mut self, prompt: &str, dialog: FileDialog, kind: FileKind, ) -> Option<FileChoice> { ... } fn clear_screen(&mut self) { ... } fn console_width(&mut self) -> Option<usize> { ... } fn script_input(&mut self) { ... } fn sleep(&mut self, milliseconds: u32) -> bool { ... } fn status_line(&mut self, text: &str) { ... } fn status_right(&mut self, text: &str) { ... } fn time(&mut self) -> Time { ... } fn local_time_zone(&mut self) -> Option<String> { ... } fn system_name(&self) -> String { ... } fn has_panes(&self) -> bool { ... } fn pane_create( &mut self, parent: Option<u32>, placement: Placement, spec: PaneSpec, ) -> Option<u32> { ... } fn pane_delete(&mut self, id: u32) { ... } fn pane_clear(&mut self, id: u32) { ... } fn pane_write(&mut self, id: u32, text: &str) { ... } fn pane_write_markup(&mut self, id: u32, markup: &str) { ... } fn pane_flush(&mut self, id: u32) { ... } fn pane_set_size(&mut self, id: u32, size: i32, units: i32, advisory: bool) { ... } fn pane_size_to_contents(&mut self, id: u32) { ... } fn pane_go_to(&mut self, id: u32, row: usize, column: usize) { ... } fn pane_info(&mut self, id: u32) -> Option<PaneInfo> { ... } fn pane_set_screen_color(&mut self, id: u32, color: u32) { ... }
}
Expand description

The services a VM needs from the system it runs on.

Required Methods§

Source

fn print(&mut self, text: &str)

Display text on the main console.

Provided Methods§

Source

fn rich_display(&self) -> Option<RichDisplay>

What the display can do beyond plain text, if it is a rich display; None for a display of text, which gets its text through Host::print, broken into lines that fit.

Source

fn print_markup(&mut self, markup: &str)

On a rich display: what the program wrote, as it wrote it, markup and all, in order. The host checks it with a rich::Checker.

Source

fn print_input(&mut self, text: &str)

On a rich display: a line the player typed, from a script, shown as the player’s own words.

Source

fn random_bytes(&mut self, buffer: &mut [u8])

Fill a buffer with unpredictable bytes, for seeding the random number generator. A host that leaves the buffer alone gives every run the same seed, which is what tests want.

Source

fn read_file(&mut self, name: &str) -> Result<Vec<u8>, FileError>

The whole contents of a file. Names are the host’s to interpret: a path on a system with a file system, a key in a browser’s storage.

Source

fn write_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError>

Create a file with the given contents, replacing any there was.

Source

fn file_info(&mut self, name: &str, follow_links: bool) -> Option<FileInfo>

What a name refers to, or None if nothing. With follow_links, a symbolic link is described by what it leads to.

File names are in one syntax on every host: parts separated by /, with . for the folder itself and .. for the one above. A name that does not start at a root is relative to wherever the host keeps the program’s files.

Source

fn delete_file(&mut self, name: &str) -> Result<(), FileError>

Delete a file.

Source

fn rename_file(&mut self, from: &str, to: &str) -> Result<(), FileError>

Give a file a new name, which must not be in use.

Source

fn create_dir(&mut self, name: &str, parents: bool) -> Result<(), FileError>

Create a directory, and with parents any directories above it that are missing.

Source

fn remove_dir(&mut self, name: &str, contents: bool) -> Result<(), FileError>

Remove a directory, which has to be empty unless contents says to delete what is in it too.

Source

fn list_dir(&mut self, name: &str) -> Option<Vec<String>>

The names in a directory, without the path to it. A host whose directories have entries for themselves and their parents includes . and ...

Source

fn absolute_path(&mut self, name: &str) -> Option<String>

The full name of a file, from a root.

Source

fn root_dirs(&mut self) -> Vec<String>

The roots of the file system: / on some systems, a list of drives on others.

Source

fn sandbox(&mut self, name: &str) -> Sandbox

Where a file is in relation to the folder the program’s file access is confined to. The default confines nothing.

Source

fn temp_file_name(&mut self) -> Option<String>

A name for a new temporary file, which does not exist yet.

Source

fn special_file(&mut self, id: i32) -> Option<String>

The name of one of the files that programs ask for by number because where they are kept is up to the system: 1 is the file of settings shared by every game that uses the standard library, and 2 the same for the web interface.

Source

fn append_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError>

Add to the end of a file, creating it if it is not there.

Source

fn read_line(&mut self) -> Input

Read a line of input from the player, without the line ending.

Source

fn read_key(&mut self) -> Input

Read one keystroke. A key that types a character is that character; Enter is a newline; any other key goes by its name in square brackets, such as [up] or [f1].

Source

fn choose_file( &mut self, prompt: &str, dialog: FileDialog, kind: FileKind, ) -> Option<FileChoice>

Ask the player for a file in a dialog of the system’s own, with the program’s prompt as its title, or None for a host that has no such dialog: the VM then asks for the file’s name as a line of input, after the prompt, as a console of text does.

Source

fn clear_screen(&mut self)

Clear the main console.

Source

fn console_width(&mut self) -> Option<usize>

The width of the main console in columns, if the host has one of its own, such as a terminal window’s. Text is broken into lines that fit. Without one the width is 80 columns.

Source

fn script_input(&mut self)

Input has just come from a script instead of from the player. A host that pauses when a screenful of text has gone by since the player last typed starts counting again from here.

Source

fn sleep(&mut self, milliseconds: u32) -> bool

Pause for a number of milliseconds. A host that can wait does, and returns true. One that cannot returns false, which stops the VM where it is; when the time has passed, the host resumes the VM, which asks again, and this time the answer is true.

Source

fn status_line(&mut self, text: &str)

Show text in the status line: the left part, which is usually the name of the player’s location.

Source

fn status_right(&mut self, text: &str)

Show text at the right of the status line, usually the score.

Source

fn time(&mut self) -> Time

The time now. A host without a clock reports the start of 1970, which also keeps tests reproducible.

Source

fn local_time_zone(&mut self) -> Option<String>

The name of the host’s time zone in the zoneinfo database, such as America/Chicago, if the host knows it. Without one, local time is UTC shifted by the offset that Host::time reports.

Source

fn system_name(&self) -> String

A name for the system the host runs on.

Source

fn has_panes(&self) -> bool

Whether the host can show panes. Without them, a program that asks for one is told it cannot have it, as on a plain console.

Source

fn pane_create( &mut self, parent: Option<u32>, placement: Placement, spec: PaneSpec, ) -> Option<u32>

Create a pane inside another, or inside the main window if parent is None: its handle, or None if the host cannot.

Source

fn pane_delete(&mut self, id: u32)

Remove a pane.

Source

fn pane_clear(&mut self, id: u32)

Remove the text in a pane.

Source

fn pane_write(&mut self, id: u32, text: &str)

Add text to a pane. The text is already broken into lines that fit.

Source

fn pane_write_markup(&mut self, id: u32, markup: &str)

On a rich display: add what the program wrote to a text pane, as it wrote it, markup and all, as Host::print_markup does for the main window. A text grid’s text still comes through Host::pane_write.

Source

fn pane_flush(&mut self, id: u32)

Show what has been written to a pane.

Source

fn pane_set_size(&mut self, id: u32, size: i32, units: i32, advisory: bool)

Change the size of a pane. See pane::Screen::set_size.

Source

fn pane_size_to_contents(&mut self, id: u32)

Make a pane as big as what it holds.

Source

fn pane_go_to(&mut self, id: u32, row: usize, column: usize)

Move where text goes next in a text grid, counting from zero.

Source

fn pane_info(&mut self, id: u32) -> Option<PaneInfo>

What a program can learn about a pane.

Source

fn pane_set_screen_color(&mut self, id: u32, color: u32)

Give a pane a background color: one of the colors the host chooses, such as pane::color::STATUS_BG, or an RGB value.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§