Skip to main content

Crate staquia

Crate staquia 

Source
Expand description

Staquia creates positions: short strings that keep the order of a list.

Sort the items by their position string and you get the order back; moving an item only changes its own position, so only one row is written to the database per change. It is the Rust version of the staquia JavaScript library: for the same system and operations, both create the same positions.

The guides (how positions work, storing them in a database, error handling) are on the documentation site, which opens with every example in Rust.

Nothing panics: every operation that can fail returns a Result with an error enum (PositionError, LexicalError) that works with ?.

§Example

use staquia::Staquia;

let system = Staquia::create('!', 'a', 'z', 5, 15, 0.15)?;

let first = system.start()?; // "mmmmm!"
let second = system.next(&first)?; // "mmmmn!"
let between = system.core(&first, &second)?; // "mmmmmn"

let mut positions = [second.to_string(), first.to_string(), between.to_string()];
positions.sort();
assert_eq!(positions, ["mmmmm!", "mmmmmn", "mmmmn!"]);

Structs§

Iter
The items of a LexicalList in their order, see LexicalList::iter.
LexicalItem
A value of a LexicalList with its position and the ids of its neighbors.
LexicalList
A list that keeps the order of your values and their positions in sync, as a doubly linked list of ids.
Options
The configuration of a Staquia system, for Staquia::create_with_options.
Position
A position: a short string that keeps the order of a list.
Rejected
An operation of a LexicalList that took ownership of a value failed: the error and the value, given back unchanged.
Staquia
A lexicographic number system that creates positions: short strings that keep the order of a list.

Enums§

CreateError
Why Staquia::create rejected a configuration.
Direction
The direction of Staquia::next and Staquia::previous, given by PositionError::EdgeReached to tell which end of N was reached.
Error
Any error of the crate, so every operation can use ? in the same function without boxing the errors. K is the type of the ids of a LexicalList, () when no list is used.
LexicalError
Why an operation of a LexicalList failed. K is the type of the ids, so the error tells which item caused it.
PositionError
Why a position could not be created.

Constants§

MAX_LENGTH
The maximum length of a position (ln + lz) of any system.

Traits§

Item
A value that can be stored in a LexicalList: it has an id and a position.

Type Aliases§

Replaced
The result of the operations that change many positions of a LexicalList at once (set, set_untrusted): the affected items (the rows to save), or the error with the values given back in a Rejected.