Struct SDoc

Source
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: SFormats

Formats that this Doc supports. It is up to the local Doc to provide formats.

§libraries: SLibraries

Libraries that this Doc can call when scripting. It is up to the local Doc to provide libraries.

Implementations§

Source§

impl SDoc

Source

pub fn new(graph: SGraph) -> Self

New document from a graph.

Source

pub fn src(src: &str, format: &str) -> Result<Self, SError>

New document from a string import format.

Source

pub fn file(path: &str, format: &str) -> Result<Self, SError>

New document from a file import.

Source

pub fn bytes(bytes: Bytes, format: &str) -> Result<Self, SError>

New document from bytes.

Source

pub fn text_file_out(&mut self, path: &str, format: &str) -> Result<(), SError>

Export this document to a text file at “path” using “format”.

Source

pub fn bin_file_out(&mut self, path: &str, format: &str) -> Result<(), SError>

Export this document to a binary file at “path” using “format”.

Source

pub fn load_format(&mut self, format: Arc<dyn Format>)

Load a format into this document.

Source

pub fn available_formats(&self) -> HashSet<String>

Available formats

Source

pub fn format_content_type(&self, format: &str) -> Option<String>

Content type for a format.

Source

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).

Source

pub fn string_import( &mut self, pid: &str, format: &str, src: &str, as_name: &str, ) -> Result<(), SError>

String import.

Source

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 .” as <as_name>;’ If isn’t supplied, “format” will be “extension”. If <as_name> isn’t supplied, the data should be imported into the current doc scope (or main root).

Source

pub fn export_string( &self, pid: &str, format: &str, node: Option<&SNodeRef>, ) -> Result<String, SError>

Export document string.i

Source

pub fn export_min_string( &self, pid: &str, format: &str, node: Option<&SNodeRef>, ) -> Result<String, SError>

Export document min string.

Source

pub fn export_bytes( &self, pid: &str, format: &str, node: Option<&SNodeRef>, ) -> Result<Bytes, SError>

Export document bytes.

Source

pub fn load_lib(&mut self, library: Arc<dyn Library>)

Load a library into this document.

Source

pub fn library(&self, lib: &str) -> Option<Arc<dyn Library>>

Get a library in this doc.

Source

pub fn available_libraries(&self) -> HashSet<String>

Available libraries

Source

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.

Source

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.

Source

pub fn fs_read_string( &mut self, pid: &str, path: &str, ) -> Result<String, SError>

Read a file to a string using the fs library.

Source

pub fn fs_read_blob(&mut self, pid: &str, path: &str) -> Result<Bytes, SError>

Read a file to a blob using the fs library.

Source

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.

Source

pub fn field(&self, path: &str, start: Option<&SNodeRef>) -> Option<&SField>

Find a field in this document with a path. Path is dot ‘.’ separated.

Source

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.

Source

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.

Source

pub fn func(&self, path: &str, start: Option<&SNodeRef>) -> Option<SDataRef>

Find a function in this document with a path. Path is dot ‘.’ separated.

Source

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.

Source

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.

Source

pub fn test(stof: &str, throw: bool, context: Option<&SNodeRef>)

Test some Stof. Will run all #test functions in ‘stof’. Set ‘throw’ to true if you want this function to panic if tests fail.

Source

pub fn run_tests( &mut self, throw: bool, context: Option<&SNodeRef>, ) -> Result<String, String>

Run the test functions on a node or within this document, throwing an error if any fail. Test functions are denoted with a #[test(<result_expr_eq>)] attribute.

Trait Implementations§

Source§

impl Clone for SDoc

Source§

fn clone(&self) -> SDoc

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SDoc

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SDoc

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SDoc

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for SDoc

§

impl !RefUnwindSafe for SDoc

§

impl Send for SDoc

§

impl Sync for SDoc

§

impl Unpin for SDoc

§

impl !UnwindSafe for SDoc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,