SysBackend

Trait SysBackend 

Source
pub trait SysBackend:
    Any
    + Send
    + Sync
    + 'static {
Show 72 methods // Required methods fn any(&self) -> &dyn Any; fn any_mut(&mut self) -> &mut dyn Any; // Provided methods fn save_error_color(&self, message: String, colored: String) { ... } fn output_enabled(&self) -> bool { ... } fn set_output_enabled(&self, enabled: bool) -> bool { ... } fn print_str_stdout(&self, s: &str) -> Result<(), String> { ... } fn print_str_stderr(&self, s: &str) -> Result<(), String> { ... } fn print_str_trace(&self, s: &str) { ... } fn show(&self, value: Value) -> Result<(), String> { ... } fn scan_line_stdin(&self) -> Result<Option<String>, String> { ... } fn scan_stdin(&self, count: Option<usize>) -> Result<Vec<u8>, String> { ... } fn scan_until_stdin(&self, delim: &[u8]) -> Result<Vec<u8>, String> { ... } fn set_raw_mode(&self, raw_mode: bool) -> Result<(), String> { ... } fn get_raw_mode(&self) -> Result<bool, String> { ... } fn var(&self, name: &str) -> Option<String> { ... } fn term_size(&self) -> Result<(usize, usize), String> { ... } fn exit(&self, status: i32) -> Result<(), String> { ... } fn file_exists(&self, path: &str) -> bool { ... } fn list_dir(&self, path: &str) -> Result<Vec<String>, String> { ... } fn is_file(&self, path: &str) -> Result<bool, String> { ... } fn delete(&self, path: &str) -> Result<(), String> { ... } fn trash(&self, path: &str) -> Result<(), String> { ... } fn read(&self, handle: Handle, count: usize) -> Result<Vec<u8>, String> { ... } fn read_all(&self, handle: Handle) -> Result<Vec<u8>, String> { ... } fn read_until( &self, handle: Handle, delim: &[u8], ) -> Result<Vec<u8>, String> { ... } fn read_lines<'a>( &self, handle: Handle, ) -> Result<ReadLinesReturnFn<'a>, String> { ... } fn write(&self, handle: Handle, contents: &[u8]) -> Result<(), String> { ... } fn seek(&self, handle: Handle, offset: StreamSeek) -> Result<(), String> { ... } fn create_file(&self, path: &Path) -> Result<Handle, String> { ... } fn open_file(&self, path: &Path, write: bool) -> Result<Handle, String> { ... } fn make_dir(&self, path: &Path) -> Result<(), String> { ... } fn file_read_all(&self, path: &Path) -> Result<Vec<u8>, String> { ... } fn file_write_all(&self, path: &Path, contents: &[u8]) -> Result<(), String> { ... } fn clipboard(&self) -> Result<String, String> { ... } fn set_clipboard(&self, contents: &str) -> Result<(), String> { ... } fn sleep(&self, seconds: f64) -> Result<(), String> { ... } fn allow_thread_spawning(&self) -> bool { ... } fn show_image( &self, image: DynamicImage, label: Option<&str>, ) -> Result<(), String> { ... } fn show_gif( &self, gif_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String> { ... } fn show_apng( &self, apng_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String> { ... } fn play_audio( &self, wave_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String> { ... } fn audio_sample_rate(&self) -> u32 { ... } fn stream_audio(&self, f: AudioStreamFn) -> Result<(), String> { ... } fn now(&self) -> f64 { ... } fn tcp_listen(&self, addr: &str) -> Result<Handle, String> { ... } fn tls_listen( &self, addr: &str, cert: &[u8], key: &[u8], ) -> Result<Handle, String> { ... } fn tcp_accept(&self, handle: Handle) -> Result<Handle, String> { ... } fn tcp_connect(&self, addr: &str) -> Result<Handle, String> { ... } fn tls_connect(&self, addr: &str) -> Result<Handle, String> { ... } fn tcp_addr(&self, handle: Handle) -> Result<SocketAddr, String> { ... } fn tcp_set_non_blocking( &self, handle: Handle, non_blocking: bool, ) -> Result<(), String> { ... } fn tcp_set_read_timeout( &self, handle: Handle, timeout: Option<Duration>, ) -> Result<(), String> { ... } fn tcp_set_write_timeout( &self, handle: Handle, timeout: Option<Duration>, ) -> Result<(), String> { ... } fn udp_bind(&self, addr: &str) -> Result<Handle, String> { ... } fn udp_recv(&self, handle: Handle) -> Result<(Vec<u8>, SocketAddr), String> { ... } fn udp_send( &self, handle: Handle, packet: &[u8], addr: &str, ) -> Result<(), String> { ... } fn udp_set_max_msg_length( &self, handle: Handle, max_len: usize, ) -> Result<(), String> { ... } fn close(&self, handle: Handle) -> Result<(), String> { ... } fn invoke(&self, path: &str) -> Result<(), String> { ... } fn run_command_inherit( &self, command: &str, args: &[&str], ) -> Result<i32, String> { ... } fn run_command_capture( &self, command: &str, args: &[&str], ) -> Result<(i32, String, String), String> { ... } fn run_command_stream( &self, command: &str, args: &[&str], ) -> Result<[Handle; 3], String> { ... } fn change_directory(&self, path: &str) -> Result<(), String> { ... } fn get_current_directory(&self) -> Result<String, String> { ... } fn webcam_capture(&self, index: usize) -> Result<RgbImage, String> { ... } fn ffi( &self, file: &str, result_ty: FfiType, name: &str, arg_tys: &[FfiArg], args: Vec<Value>, ) -> Result<Value, String> { ... } fn mem_copy(&self, ptr: MetaPtr, len: usize) -> Result<Value, String> { ... } fn mem_set( &self, ptr: MetaPtr, idx: usize, value: Value, ) -> Result<(), String> { ... } fn mem_free(&self, ptr: &MetaPtr) -> Result<(), String> { ... } fn load_git_module( &self, url: &str, target: GitTarget, ) -> Result<PathBuf, String> { ... } fn timezone(&self) -> Result<f64, String> { ... } fn breakpoint(&self, env: &Uiua) -> Result<bool, String> { ... }
}
Expand description

Trait for defining a system backend

Required Methods§

Source

fn any(&self) -> &dyn Any

Cast the backend to &dyn Any

Source

fn any_mut(&mut self) -> &mut dyn Any

Cast the backend to &mut dyn Any

Provided Methods§

Source

fn save_error_color(&self, message: String, colored: String)

Save a color-formatted version of an error message for later printing

Source

fn output_enabled(&self) -> bool

Check whether output is enabled

Source

fn set_output_enabled(&self, enabled: bool) -> bool

Set whether output should be enabled

Returns the previous value.

It is the trait implementor’s responsibility to ensure that this value is respected.

Source

fn print_str_stdout(&self, s: &str) -> Result<(), String>

Print a string (without a newline) to stdout

Source

fn print_str_stderr(&self, s: &str) -> Result<(), String>

Print a string (without a newline) to stderr

Source

fn print_str_trace(&self, s: &str)

Print a string that was create by trace

Source

fn show(&self, value: Value) -> Result<(), String>

Show a value

Source

fn scan_line_stdin(&self) -> Result<Option<String>, String>

Read a line from stdin

Should return Ok(None) if EOF is reached.

Source

fn scan_stdin(&self, count: Option<usize>) -> Result<Vec<u8>, String>

Read a number of bytes from stdin

If count is None, read until EOF.

Source

fn scan_until_stdin(&self, delim: &[u8]) -> Result<Vec<u8>, String>

Read from stdin until a delimiter is reached

Source

fn set_raw_mode(&self, raw_mode: bool) -> Result<(), String>

Set the terminal to raw mode

Source

fn get_raw_mode(&self) -> Result<bool, String>

Get the terminal raw mode

Source

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

Get an environment variable

Source

fn term_size(&self) -> Result<(usize, usize), String>

Get the size of the terminal

Source

fn exit(&self, status: i32) -> Result<(), String>

Exit the program with a status code

Source

fn file_exists(&self, path: &str) -> bool

Check if a file or directory exists

Source

fn list_dir(&self, path: &str) -> Result<Vec<String>, String>

List the contents of a directory

Source

fn is_file(&self, path: &str) -> Result<bool, String>

Check if a path is a file

Source

fn delete(&self, path: &str) -> Result<(), String>

Delete a file or directory

Source

fn trash(&self, path: &str) -> Result<(), String>

Move a file or directory to the trash

Source

fn read(&self, handle: Handle, count: usize) -> Result<Vec<u8>, String>

Read at most count bytes from a stream

Source

fn read_all(&self, handle: Handle) -> Result<Vec<u8>, String>

Read from a stream until the end

Source

fn read_until(&self, handle: Handle, delim: &[u8]) -> Result<Vec<u8>, String>

Read from a stream until a delimiter is reached

Source

fn read_lines<'a>( &self, handle: Handle, ) -> Result<ReadLinesReturnFn<'a>, String>

Read lines from a stream

Source

fn write(&self, handle: Handle, contents: &[u8]) -> Result<(), String>

Write bytes to a stream

Source

fn seek(&self, handle: Handle, offset: StreamSeek) -> Result<(), String>

Go to an absolute file position

Source

fn create_file(&self, path: &Path) -> Result<Handle, String>

Create a file

Source

fn open_file(&self, path: &Path, write: bool) -> Result<Handle, String>

Open a file

Source

fn make_dir(&self, path: &Path) -> Result<(), String>

Create a directory

Source

fn file_read_all(&self, path: &Path) -> Result<Vec<u8>, String>

Read all bytes from a file

Source

fn file_write_all(&self, path: &Path, contents: &[u8]) -> Result<(), String>

Write all bytes to a file

Source

fn clipboard(&self) -> Result<String, String>

Get the clipboard contents

Source

fn set_clipboard(&self, contents: &str) -> Result<(), String>

Set the clipboard contents

Source

fn sleep(&self, seconds: f64) -> Result<(), String>

Sleep the current thread for seconds seconds

Source

fn allow_thread_spawning(&self) -> bool

Whether thread spawning is allowed

Source

fn show_image( &self, image: DynamicImage, label: Option<&str>, ) -> Result<(), String>

Show an image

Source

fn show_gif( &self, gif_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String>

Show a GIF

Source

fn show_apng( &self, apng_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String>

Show an APNG

Source

fn play_audio( &self, wave_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String>

Play audio from WAV bytes

Source

fn audio_sample_rate(&self) -> u32

Get the audio sample rate

Source

fn stream_audio(&self, f: AudioStreamFn) -> Result<(), String>

Stream audio

Source

fn now(&self) -> f64

The result of the now function

Should be in seconds

Source

fn tcp_listen(&self, addr: &str) -> Result<Handle, String>

Create a TCP listener and bind it to an address

Source

fn tls_listen( &self, addr: &str, cert: &[u8], key: &[u8], ) -> Result<Handle, String>

Create a TLS listener and bind it to an address

Source

fn tcp_accept(&self, handle: Handle) -> Result<Handle, String>

Accept a connection with a TCP listener

Source

fn tcp_connect(&self, addr: &str) -> Result<Handle, String>

Create a TCP socket and connect it to an address

Source

fn tls_connect(&self, addr: &str) -> Result<Handle, String>

Create a TCP socket with TLS support and connect it to an address

Source

fn tcp_addr(&self, handle: Handle) -> Result<SocketAddr, String>

Get the connection address of a TCP socket or listener

Source

fn tcp_set_non_blocking( &self, handle: Handle, non_blocking: bool, ) -> Result<(), String>

Set a TCP socket to non-blocking mode

Source

fn tcp_set_read_timeout( &self, handle: Handle, timeout: Option<Duration>, ) -> Result<(), String>

Set the read timeout of a TCP socket

Source

fn tcp_set_write_timeout( &self, handle: Handle, timeout: Option<Duration>, ) -> Result<(), String>

Set the write timeout of a TCP socket

Source

fn udp_bind(&self, addr: &str) -> Result<Handle, String>

Create a UDP socket and bind it to an address

Source

fn udp_recv(&self, handle: Handle) -> Result<(Vec<u8>, SocketAddr), String>

Receive a single datagram on a UDP socket

Source

fn udp_send( &self, handle: Handle, packet: &[u8], addr: &str, ) -> Result<(), String>

Send a datagram to an address over a UDP socket

Source

fn udp_set_max_msg_length( &self, handle: Handle, max_len: usize, ) -> Result<(), String>

Set the maximum message length for a UDP socket

Source

fn close(&self, handle: Handle) -> Result<(), String>

Close a stream

Source

fn invoke(&self, path: &str) -> Result<(), String>

Invoke a path with the system’s default program

Source

fn run_command_inherit( &self, command: &str, args: &[&str], ) -> Result<i32, String>

Run a command, inheriting standard IO

Source

fn run_command_capture( &self, command: &str, args: &[&str], ) -> Result<(i32, String, String), String>

Run a command, capturing standard IO

Source

fn run_command_stream( &self, command: &str, args: &[&str], ) -> Result<[Handle; 3], String>

Run a command and return an IO stream handle

Source

fn change_directory(&self, path: &str) -> Result<(), String>

Change the current directory

Source

fn get_current_directory(&self) -> Result<String, String>

Get the current directory

Source

fn webcam_capture(&self, index: usize) -> Result<RgbImage, String>

Capture an image from the webcam

Source

fn ffi( &self, file: &str, result_ty: FfiType, name: &str, arg_tys: &[FfiArg], args: Vec<Value>, ) -> Result<Value, String>

Call a foreign function interface

Source

fn mem_copy(&self, ptr: MetaPtr, len: usize) -> Result<Value, String>

Copy the data from a pointer into an array

Source

fn mem_set(&self, ptr: MetaPtr, idx: usize, value: Value) -> Result<(), String>

Write data from an array into a pointer

Source

fn mem_free(&self, ptr: &MetaPtr) -> Result<(), String>

Free a pointer

Source

fn load_git_module( &self, url: &str, target: GitTarget, ) -> Result<PathBuf, String>

Load a git repo as a module

The returned path should be loadable via SysBackend::file_read_all

Source

fn timezone(&self) -> Result<f64, String>

Get the local timezone offset in hours

Source

fn breakpoint(&self, env: &Uiua) -> Result<bool, String>

Hit a breakpoint

Returns whether to continue the program

Trait Implementations§

Source§

impl Debug for dyn SysBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§