Skip to content

Commit

Permalink
doc polished
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 14, 2023
1 parent 6b631c1 commit 986f984
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ impl Sodg {

/// Check all alerts for the given list of vertices.
///
/// If any of them
/// have any issues, `Err` is returned.
/// If any of them have any issues, `Err` is returned.
pub fn validate(&self, vx: Vec<u32>) -> Result<()> {
if self.alerts_active {
for a in self.alerts.iter() {
Expand Down
5 changes: 3 additions & 2 deletions src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::collections::VecDeque;
impl Sodg {
/// Attempt to collect the vertex (delete it from the graph).
///
/// If there are no edges leading to it, then it is deleted and all its children are collected.
/// Otherwise, nothing happens.
/// If there are no edges leading to it, then it is deleted and
/// all its children are collected.
/// Otherwise, nothing happens. For example:
///
/// ```
/// use sodg::{Hex, Sodg};
Expand Down
38 changes: 38 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl Display for Hex {
impl Hex {
/// Make an empty `Hex`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::empty();
Expand All @@ -82,6 +84,8 @@ impl Hex {

/// Take the bytes contained.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from(2);
Expand All @@ -96,6 +100,8 @@ impl Hex {

/// Count, how many bytes are in there.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::empty();
Expand All @@ -110,6 +116,8 @@ impl Hex {

/// Create a new [`Hex`] from slice, in appropriate mode.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_slice(&[0xDE, 0xAD]);
Expand All @@ -134,6 +142,8 @@ impl Hex {

/// Create a new [`Hex`] from `Vec<u8>`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec(vec![0xCA, 0xFE]);
Expand All @@ -149,6 +159,8 @@ impl Hex {

/// Create a new [`Hex`] from `String`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_string_bytes("Ура!".to_string());
Expand All @@ -160,6 +172,8 @@ impl Hex {

/// Create a new [`Hex`] from the bytes composing `&str`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_str_bytes("Ура!");
Expand All @@ -171,6 +185,8 @@ impl Hex {

/// Is it empty and has no data (not a single byte)?
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec(vec![]);
Expand All @@ -182,6 +198,8 @@ impl Hex {

/// Turn it into `bool`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec([0x01].to_vec());
Expand All @@ -193,6 +211,8 @@ impl Hex {

/// Turn it into `i64`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A].to_vec());
Expand All @@ -208,6 +228,8 @@ impl Hex {

/// Turn it into `f64`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec([0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18].to_vec());
Expand All @@ -223,6 +245,8 @@ impl Hex {

/// Turn it into `String` in UTF-8 encoding.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec([0x41, 0x42].to_vec());
Expand All @@ -237,6 +261,8 @@ impl Hex {

/// Turn it into a hexadecimal string.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_vec([0xCA, 0xFE].to_vec());
Expand Down Expand Up @@ -277,6 +303,8 @@ impl Hex {

/// Take one byte.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_str_bytes("你好");
Expand All @@ -290,6 +318,8 @@ impl Hex {
/// Skip a few bytes at the beginning and return the rest
/// as a new instance of `Hex`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from_str_bytes("Hello, world!");
Expand All @@ -301,6 +331,8 @@ impl Hex {

/// Create a new `Hex`, which is a concatenation of `self` and `h`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let a = Hex::from_slice("dead".as_bytes());
Expand Down Expand Up @@ -334,6 +366,8 @@ impl Hex {
impl From<i64> for Hex {
/// Make a new `Hex` from `i64`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from(65536);
Expand All @@ -347,6 +381,8 @@ impl From<i64> for Hex {
impl From<f64> for Hex {
/// Make a new `Hex` from `f64`.
///
/// For example:
///
/// ```
/// use std::f64::consts::PI;
/// use sodg::Hex;
Expand All @@ -361,6 +397,8 @@ impl From<f64> for Hex {
impl From<bool> for Hex {
/// Create a new [`Hex`] from `bool`.
///
/// For example:
///
/// ```
/// use sodg::Hex;
/// let d = Hex::from(true);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) use crate::vertex::Vertex;
/// A struct that represents a Surging Object DiGraph (SODG).
///
/// You add vertices to it, bind them one to one with edges,
/// put data into some of them, and read data back:
/// put data into some of them, and read data back, for example:
///
/// ```
/// use sodg::Sodg;
Expand Down
2 changes: 2 additions & 0 deletions src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ impl Sodg {
///
/// Emptiness means that not a single vertex is in the graph.
///
/// For example:
///
/// ```
/// use sodg::Sodg;
/// let mut sodg = Sodg::empty();
Expand Down
6 changes: 2 additions & 4 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ impl Sodg {

/// Make an edge `e1` from vertex `v1` to vertex `v2` and put `a` label on it.
///
/// If the
/// label is not equal to `"ρ"`, makes two backward edges from `v2` to `v1`
/// and label them as `"ρ"` an `"𝜎"`. For example:
/// For example:
///
/// ```
/// use sodg::Sodg;
Expand All @@ -71,7 +69,7 @@ impl Sodg {
///
/// If `v1` equals to `v2`, an `Err` will be returned.
///
/// The label `a` can't be empty. If it's empty, an `Err` will be returned.
/// The label `a` can't be empty. If it is empty, an `Err` will be returned.
pub fn bind(&mut self, v1: u32, v2: u32, a: &str) -> Result<()> {
let vtx1 = self
.vertices
Expand Down
2 changes: 2 additions & 0 deletions src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl Script {
/// 2) a variable started with `$`, 3) an attribute name, or
/// 4) data in `XX-XX-...` hexadecimal format.
///
/// For example:
///
/// ```
/// use sodg::Script;
/// use sodg::Sodg;
Expand Down

0 comments on commit 986f984

Please sign in to comment.