Skip to content

Commit

Permalink
#17 more doc
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 14, 2022
1 parent d38904a commit 0ab5fde
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
//! [`Sodg::bind`], and [`Sodg::put`]) and then decides itself when
//! it's time to delete some vertices (something similar to
//! "garbage collection"). For example, here is how you create a simple
//! graph:
//! graph with two vertices and an edge between them:
//!
//! ```
//! use sodg::Sodg;
//! let mut sodg = Sodg::empty();
//! sodg.add(0).unwrap();
//! sodg.add(1).unwrap();
//! sodg.bind(0, 1, "foo").unwrap();
//! ```

#![doc(html_root_url = "https://docs.rs/sodg/0.0.0")]
Expand Down Expand Up @@ -84,11 +89,45 @@ pub struct Sodg {

/// It is an object-oriented representation of binary data
/// in hexadecimal format, which can be put into vertices of the graph.
/// You can create it from Rust primitives:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_i64(65534);
/// assert_eq!("00-00-00-00-00-00-FF-FE", d.print());
/// ```
///
/// Then, you can turn it back to Rust primitives:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_i64(65534);
/// assert_eq!(65534, d.to_i64().unwrap());
/// ```
#[derive(Serialize, Deserialize)]
pub struct Hex {
bytes: Vec<u8>,
}

/// It is a wrapper of a plain text with graph-modifying
/// instructions, for example:
///
/// ```text
/// ADD(0);
/// ADD($ν1); # adding new vertex
/// BIND(0, $ν1, foo);
/// PUT($ν1, d0-bf-D1-80-d0-B8-d0-b2-d0-b5-d1-82);
/// ```
///
/// In the script you can use "variables", similar to `$ν1` used
/// in the text above. They will be replaced by autogenerated numbers
/// during the deployment of this script to a [`Sodg`].
pub struct Script {
txt: String,
vars: HashMap<String, u32>,
root: u32,
}

#[derive(Clone, Serialize, Deserialize, Eq, PartialOrd, PartialEq, Ord)]
struct Edge {
pub to: u32,
Expand All @@ -101,12 +140,6 @@ struct Vertex {
pub data: Hex,
}

pub struct Script {
txt: String,
vars: HashMap<String, u32>,
root: u32,
}

#[cfg(test)]
use simple_logger::SimpleLogger;

Expand Down

0 comments on commit 0ab5fde

Please sign in to comment.