pub struct SDoc {
pub graph: SGraph,
pub perms: DocPermissions,
pub types: CustomTypes,
pub formats: SFormats,
pub libraries: SLibraries,
/* private fields */
}Expand description
Stof Document. Holds a Graph, containing the data contained within this document as well as any permissions, libraries, etc… needed for this document to manipulate itself.
Fields§
§graph: SGraph§perms: DocPermissions§types: CustomTypes§formats: SFormatsFormats that this Doc supports. It is up to the local Doc to provide formats.
libraries: SLibrariesLibraries that this Doc can call when scripting. It is up to the local Doc to provide libraries.
Implementations§
Source§impl SDoc
impl SDoc
Sourcepub fn src(src: &str, format: &str) -> Result<Self, SError>
pub fn src(src: &str, format: &str) -> Result<Self, SError>
New document from a string import format.
Sourcepub fn text_file_out(&mut self, path: &str, format: &str) -> Result<(), SError>
pub fn text_file_out(&mut self, path: &str, format: &str) -> Result<(), SError>
Export this document to a text file at “path” using “format”.
Sourcepub fn bin_file_out(&mut self, path: &str, format: &str) -> Result<(), SError>
pub fn bin_file_out(&mut self, path: &str, format: &str) -> Result<(), SError>
Export this document to a binary file at “path” using “format”.
Sourcepub fn load_format(&mut self, format: Arc<dyn Format>)
pub fn load_format(&mut self, format: Arc<dyn Format>)
Load a format into this document.
Sourcepub fn available_formats(&self) -> HashSet<String>
pub fn available_formats(&self) -> HashSet<String>
Available formats
Sourcepub fn format_content_type(&self, format: &str) -> Option<String>
pub fn format_content_type(&self, format: &str) -> Option<String>
Content type for a format.
Sourcepub fn header_import(
&mut self,
pid: &str,
format: &str,
content_type: &str,
bytes: &mut Bytes,
as_name: &str,
) -> Result<(), SError>
pub fn header_import( &mut self, pid: &str, format: &str, content_type: &str, bytes: &mut Bytes, as_name: &str, ) -> Result<(), SError>
Header import (content type with bytes).
Sourcepub fn string_import(
&mut self,
pid: &str,
format: &str,
src: &str,
as_name: &str,
) -> Result<(), SError>
pub fn string_import( &mut self, pid: &str, format: &str, src: &str, as_name: &str, ) -> Result<(), SError>
String import.
Sourcepub fn file_import(
&mut self,
pid: &str,
format: &str,
full_path: &str,
extension: &str,
as_name: &str,
) -> Result<(), SError>
pub fn file_import( &mut self, pid: &str, format: &str, full_path: &str, extension: &str, as_name: &str, ) -> Result<(), SError>
File import.
Stof Syntax: ‘import
Sourcepub fn export_string(
&self,
pid: &str,
format: &str,
node: Option<&SNodeRef>,
) -> Result<String, SError>
pub fn export_string( &self, pid: &str, format: &str, node: Option<&SNodeRef>, ) -> Result<String, SError>
Export document string.i
Sourcepub fn export_min_string(
&self,
pid: &str,
format: &str,
node: Option<&SNodeRef>,
) -> Result<String, SError>
pub fn export_min_string( &self, pid: &str, format: &str, node: Option<&SNodeRef>, ) -> Result<String, SError>
Export document min string.
Sourcepub fn export_bytes(
&self,
pid: &str,
format: &str,
node: Option<&SNodeRef>,
) -> Result<Bytes, SError>
pub fn export_bytes( &self, pid: &str, format: &str, node: Option<&SNodeRef>, ) -> Result<Bytes, SError>
Export document bytes.
Sourcepub fn available_libraries(&self) -> HashSet<String>
pub fn available_libraries(&self) -> HashSet<String>
Available libraries
Sourcepub fn fs_write_string(
&mut self,
pid: &str,
path: &str,
contents: &str,
) -> Result<(), SError>
pub fn fs_write_string( &mut self, pid: &str, path: &str, contents: &str, ) -> Result<(), SError>
Write a string to a file using the fs library.
Sourcepub fn fs_write_blob(
&mut self,
pid: &str,
path: &str,
contents: Vec<u8>,
) -> Result<(), SError>
pub fn fs_write_blob( &mut self, pid: &str, path: &str, contents: Vec<u8>, ) -> Result<(), SError>
Write a blob to a file using the fs library.
Sourcepub fn fs_read_string(
&mut self,
pid: &str,
path: &str,
) -> Result<String, SError>
pub fn fs_read_string( &mut self, pid: &str, path: &str, ) -> Result<String, SError>
Read a file to a string using the fs library.
Sourcepub fn fs_read_blob(&mut self, pid: &str, path: &str) -> Result<Bytes, SError>
pub fn fs_read_blob(&mut self, pid: &str, path: &str) -> Result<Bytes, SError>
Read a file to a blob using the fs library.
Sourcepub fn get(&mut self, path: &str, start: Option<&SNodeRef>) -> Option<SVal>
pub fn get(&mut self, path: &str, start: Option<&SNodeRef>) -> Option<SVal>
Get a value from this document by path. If the path points to a field, the value will be retrieved. If the path points to a function, it will be called.
Sourcepub fn field(&self, path: &str, start: Option<&SNodeRef>) -> Option<&SField>
pub fn field(&self, path: &str, start: Option<&SNodeRef>) -> Option<&SField>
Find a field in this document with a path. Path is dot ‘.’ separated.
Sourcepub fn run_file(file: &str, throw: bool)
pub fn run_file(file: &str, throw: bool)
Run some Stof in a file. Will run all #[main] functions. Set ‘throw’ to true if you want this function to panic if tests fail.
Sourcepub fn run(
&mut self,
context: Option<&SNodeRef>,
attribute: Option<String>,
) -> Result<(), String>
pub fn run( &mut self, context: Option<&SNodeRef>, attribute: Option<String>, ) -> Result<(), String>
Run the main functions on a node or within this document. Main functions are denoted with an #[main] attribute in the text format. This is the default attribute to run.
Sourcepub fn func(&self, path: &str, start: Option<&SNodeRef>) -> Option<SDataRef>
pub fn func(&self, path: &str, start: Option<&SNodeRef>) -> Option<SDataRef>
Find a function in this document with a path. Path is dot ‘.’ separated.
Sourcepub fn call_func(
&mut self,
path: &str,
start: Option<&SNodeRef>,
params: Vec<SVal>,
) -> Result<SVal, SError>
pub fn call_func( &mut self, path: &str, start: Option<&SNodeRef>, params: Vec<SVal>, ) -> Result<SVal, SError>
Call a function in this document with a path.
Sourcepub fn test_file(file: &str, throw: bool)
pub fn test_file(file: &str, throw: bool)
Test some Stof in a file. Will run all #test functions. Set ‘throw’ to true if you want this function to panic if tests fail.