# Suzu Runtime / Notation Szun is a library for defining, manipulating, and formatting structured, dynamically-typed data. # Documentation ## Conventions ### Namespacing Examples in this documentation will assume inclusion of the szun namespace. Practical examples should use `szun::` or `use szun::{...};` in limited scopes. ## Type Building Type building functions are used to generate identifiers used in the construction of complex data types. * `varying()` * `boolean()` * `natural()` * `integer()` * `block(size)` * `sequence()` * `array(size, type)` * `list(type)` * `schema()` * `record(schema)` ### Example This example produces an identifier representing block of 4 bytes, which can be used to construct a list containing that type. ``` let type_id = block(4); let list = List::new(type_id); ``` ## Global Functions `acquire(type) -> Reference` Allocate a new instance of the provided type. ``` let refer = acquire(list(integer())); ``` --- `release(refer:Reference)` Destruct and deallocate a type. ``` release(refer); ``` > Warning: To avoid access violations, `release()` should not be used with interface objects, such as Boolean. --- `encode(refer:Reference) -> vec` > Not implemented --- `decode(data:Vec) -> Reference` > Not implemented --- ## Language Compiler > Not implemented ## Common Methods `new() -> Self` ``` let value = Integer::new(); ``` --- `from(refer:Reference) -> Result` ``` match Integer::from(list.at(0)) { Ok(int) => { println!("Integer: {}", int.get()); } Err(_) => { println!("Not Integer"); } } ``` --- `with(value) -> Self` ``` let b = Boolean::with(true); ``` --- `*Dereference -> Reference` ``` let refer = *Integer::new(); ``` --- ## Varying Stores a value of any other type. `is_null() -> bool` --- `get() -> Reference` ``` let var = Varying::with(*Boolean::with(true)); let value = Boolean::from(var.get()).unwrap(); ``` --- `set(refer:Reference)` ``` let var = Varying::new(); var.set(*Sequence::with("Hello!")); ``` --- ## Boolean Stores the value true or false. `get() -> bool` ``` let value = Boolean::with(true); if value.get() { println!("True"); } ``` --- `set(value:bool)` ``` let mut value = Boolean::new(); value.set(true); ``` --- ## Natural Stores a non-negative integer value. `get() -> u64` ``` let value = Integer::with(-1); println!("{}", value.get()); ``` --- `set(value:u64)` ``` let mut value = Integer::new(); value.set(-273); ``` --- ## Integer Stores a signed integer value. `get() -> i64` ``` let value = Integer::with(-1); println!("{}", value.get()); ``` --- `set(value:i64)` ``` let mut value = Integer::new(); value.set(-273); ``` --- ## Block Constant-sized series of bytes. `new(size:usize) -> Block` --- `length() -> usize` --- `get() -> Vec` --- `set(data:Vec)` --- ## Sequence Variable-sized series of bytes. `length() -> usize` --- `get() -> String` --- `get_raw() -> Vec` --- `set(data:&str)` --- `set_raw(data:Vec)` --- ## Array Constant-sized, ordered collection of items. `new(size:usize, type_id:usize) -> Array` --- `length() -> usize` --- `at(index:usize) -> Reference` --- `set(index:usize, refer:Reference)` --- ## List Variable-sized, ordered collection of items. `new(type_id:usize) -> List` --- `length() -> usize` --- `capacity() -> usize` --- `at(index:usize) -> Reference` --- `set(index:usize, refer:Reference)` --- `insert(index:usize, refer:Reference)` --- `remove(index:usize)` --- `reserve(capacity:usize)` --- `clear()` --- ## Schema Definition of an abstract structure composed of named items. `get(index:usize) -> usize` --- `add(type_id:usize) -> usize` --- `remove(index:usize)` --- `assign(key:&str, type_id:usize) -> usize` --- `map(key:&str, index:usize)` --- `unmap(key:&str)` --- `clear()` --- `bind(id:usize)` --- ## Record Instance of a schema. `new(schema_id:usize) -> Record` --- `at(index:usize) -> Reference` --- `set(index:usize, source:Reference)` --- `keyof(index:usize) -> String` --- `indexof(key:&str) -> usize` ---