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§
Provided Methods§
Sourcefn save_error_color(&self, message: String, colored: String)
fn save_error_color(&self, message: String, colored: String)
Save a color-formatted version of an error message for later printing
Sourcefn output_enabled(&self) -> bool
fn output_enabled(&self) -> bool
Check whether output is enabled
Sourcefn set_output_enabled(&self, enabled: bool) -> bool
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.
Sourcefn print_str_stdout(&self, s: &str) -> Result<(), String>
fn print_str_stdout(&self, s: &str) -> Result<(), String>
Print a string (without a newline) to stdout
Sourcefn print_str_stderr(&self, s: &str) -> Result<(), String>
fn print_str_stderr(&self, s: &str) -> Result<(), String>
Print a string (without a newline) to stderr
Sourcefn print_str_trace(&self, s: &str)
fn print_str_trace(&self, s: &str)
Print a string that was create by trace
Sourcefn scan_line_stdin(&self) -> Result<Option<String>, String>
fn scan_line_stdin(&self) -> Result<Option<String>, String>
Read a line from stdin
Should return Ok(None) if EOF is reached.
Sourcefn scan_stdin(&self, count: Option<usize>) -> Result<Vec<u8>, String>
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.
Sourcefn scan_until_stdin(&self, delim: &[u8]) -> Result<Vec<u8>, String>
fn scan_until_stdin(&self, delim: &[u8]) -> Result<Vec<u8>, String>
Read from stdin until a delimiter is reached
Sourcefn get_raw_mode(&self) -> Result<bool, String>
fn get_raw_mode(&self) -> Result<bool, String>
Get the terminal raw mode
Sourcefn file_exists(&self, path: &str) -> bool
fn file_exists(&self, path: &str) -> bool
Check if a file or directory exists
Sourcefn read(&self, handle: Handle, count: usize) -> Result<Vec<u8>, String>
fn read(&self, handle: Handle, count: usize) -> Result<Vec<u8>, String>
Read at most count bytes from a stream
Sourcefn read_until(&self, handle: Handle, delim: &[u8]) -> Result<Vec<u8>, String>
fn read_until(&self, handle: Handle, delim: &[u8]) -> Result<Vec<u8>, String>
Read from a stream until a delimiter is reached
Sourcefn read_lines<'a>(
&self,
handle: Handle,
) -> Result<ReadLinesReturnFn<'a>, String>
fn read_lines<'a>( &self, handle: Handle, ) -> Result<ReadLinesReturnFn<'a>, String>
Read lines from a stream
Sourcefn seek(&self, handle: Handle, offset: StreamSeek) -> Result<(), String>
fn seek(&self, handle: Handle, offset: StreamSeek) -> Result<(), String>
Go to an absolute file position
Sourcefn file_write_all(&self, path: &Path, contents: &[u8]) -> Result<(), String>
fn file_write_all(&self, path: &Path, contents: &[u8]) -> Result<(), String>
Write all bytes to a file
Sourcefn sleep(&self, seconds: f64) -> Result<(), String>
fn sleep(&self, seconds: f64) -> Result<(), String>
Sleep the current thread for seconds seconds
Sourcefn allow_thread_spawning(&self) -> bool
fn allow_thread_spawning(&self) -> bool
Whether thread spawning is allowed
Sourcefn show_image(
&self,
image: DynamicImage,
label: Option<&str>,
) -> Result<(), String>
fn show_image( &self, image: DynamicImage, label: Option<&str>, ) -> Result<(), String>
Show an image
Sourcefn show_gif(
&self,
gif_bytes: Vec<u8>,
label: Option<&str>,
) -> Result<(), String>
fn show_gif( &self, gif_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String>
Show a GIF
Sourcefn show_apng(
&self,
apng_bytes: Vec<u8>,
label: Option<&str>,
) -> Result<(), String>
fn show_apng( &self, apng_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String>
Show an APNG
Sourcefn play_audio(
&self,
wave_bytes: Vec<u8>,
label: Option<&str>,
) -> Result<(), String>
fn play_audio( &self, wave_bytes: Vec<u8>, label: Option<&str>, ) -> Result<(), String>
Play audio from WAV bytes
Sourcefn audio_sample_rate(&self) -> u32
fn audio_sample_rate(&self) -> u32
Get the audio sample rate
Sourcefn stream_audio(&self, f: AudioStreamFn) -> Result<(), String>
fn stream_audio(&self, f: AudioStreamFn) -> Result<(), String>
Stream audio
Sourcefn tcp_listen(&self, addr: &str) -> Result<Handle, String>
fn tcp_listen(&self, addr: &str) -> Result<Handle, String>
Create a TCP listener and bind it to an address
Sourcefn tls_listen(
&self,
addr: &str,
cert: &[u8],
key: &[u8],
) -> Result<Handle, String>
fn tls_listen( &self, addr: &str, cert: &[u8], key: &[u8], ) -> Result<Handle, String>
Create a TLS listener and bind it to an address
Sourcefn tcp_accept(&self, handle: Handle) -> Result<Handle, String>
fn tcp_accept(&self, handle: Handle) -> Result<Handle, String>
Accept a connection with a TCP listener
Sourcefn tcp_connect(&self, addr: &str) -> Result<Handle, String>
fn tcp_connect(&self, addr: &str) -> Result<Handle, String>
Create a TCP socket and connect it to an address
Sourcefn tls_connect(&self, addr: &str) -> Result<Handle, String>
fn tls_connect(&self, addr: &str) -> Result<Handle, String>
Create a TCP socket with TLS support and connect it to an address
Sourcefn tcp_addr(&self, handle: Handle) -> Result<SocketAddr, String>
fn tcp_addr(&self, handle: Handle) -> Result<SocketAddr, String>
Get the connection address of a TCP socket or listener
Sourcefn tcp_set_non_blocking(
&self,
handle: Handle,
non_blocking: bool,
) -> Result<(), String>
fn tcp_set_non_blocking( &self, handle: Handle, non_blocking: bool, ) -> Result<(), String>
Set a TCP socket to non-blocking mode
Sourcefn tcp_set_read_timeout(
&self,
handle: Handle,
timeout: Option<Duration>,
) -> Result<(), String>
fn tcp_set_read_timeout( &self, handle: Handle, timeout: Option<Duration>, ) -> Result<(), String>
Set the read timeout of a TCP socket
Sourcefn tcp_set_write_timeout(
&self,
handle: Handle,
timeout: Option<Duration>,
) -> Result<(), String>
fn tcp_set_write_timeout( &self, handle: Handle, timeout: Option<Duration>, ) -> Result<(), String>
Set the write timeout of a TCP socket
Sourcefn udp_bind(&self, addr: &str) -> Result<Handle, String>
fn udp_bind(&self, addr: &str) -> Result<Handle, String>
Create a UDP socket and bind it to an address
Sourcefn udp_recv(&self, handle: Handle) -> Result<(Vec<u8>, SocketAddr), String>
fn udp_recv(&self, handle: Handle) -> Result<(Vec<u8>, SocketAddr), String>
Receive a single datagram on a UDP socket
Sourcefn udp_send(
&self,
handle: Handle,
packet: &[u8],
addr: &str,
) -> Result<(), String>
fn udp_send( &self, handle: Handle, packet: &[u8], addr: &str, ) -> Result<(), String>
Send a datagram to an address over a UDP socket
Sourcefn udp_set_max_msg_length(
&self,
handle: Handle,
max_len: usize,
) -> Result<(), String>
fn udp_set_max_msg_length( &self, handle: Handle, max_len: usize, ) -> Result<(), String>
Set the maximum message length for a UDP socket
Sourcefn invoke(&self, path: &str) -> Result<(), String>
fn invoke(&self, path: &str) -> Result<(), String>
Invoke a path with the system’s default program
Sourcefn run_command_inherit(
&self,
command: &str,
args: &[&str],
) -> Result<i32, String>
fn run_command_inherit( &self, command: &str, args: &[&str], ) -> Result<i32, String>
Run a command, inheriting standard IO
Sourcefn run_command_capture(
&self,
command: &str,
args: &[&str],
) -> Result<(i32, String, String), String>
fn run_command_capture( &self, command: &str, args: &[&str], ) -> Result<(i32, String, String), String>
Run a command, capturing standard IO
Sourcefn run_command_stream(
&self,
command: &str,
args: &[&str],
) -> Result<[Handle; 3], String>
fn run_command_stream( &self, command: &str, args: &[&str], ) -> Result<[Handle; 3], String>
Run a command and return an IO stream handle
Sourcefn get_current_directory(&self) -> Result<String, String>
fn get_current_directory(&self) -> Result<String, String>
Get the current directory
Sourcefn webcam_capture(&self, index: usize) -> Result<RgbImage, String>
fn webcam_capture(&self, index: usize) -> Result<RgbImage, String>
Capture an image from the webcam
Sourcefn ffi(
&self,
file: &str,
result_ty: FfiType,
name: &str,
arg_tys: &[FfiArg],
args: Vec<Value>,
) -> Result<Value, String>
fn ffi( &self, file: &str, result_ty: FfiType, name: &str, arg_tys: &[FfiArg], args: Vec<Value>, ) -> Result<Value, String>
Call a foreign function interface
Sourcefn mem_copy(&self, ptr: MetaPtr, len: usize) -> Result<Value, String>
fn mem_copy(&self, ptr: MetaPtr, len: usize) -> Result<Value, String>
Copy the data from a pointer into an array
Sourcefn mem_set(&self, ptr: MetaPtr, idx: usize, value: Value) -> Result<(), String>
fn mem_set(&self, ptr: MetaPtr, idx: usize, value: Value) -> Result<(), String>
Write data from an array into a pointer
Sourcefn load_git_module(
&self,
url: &str,
target: GitTarget,
) -> Result<PathBuf, String>
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