aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: af7de7e2649e42e3ca9541a5f3039137222f8451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! enstate: state next to the store (docs/design.md).
//!
//! * [`name`]: names of channels and slots, and addresses;
//! * [`media`]: types, as media types;
//! * [`schema`]: what a generation accepts;
//! * [`content`]: the entries of one channel, and records in them;
//! * [`submission`]: what gets handed to the host;
//! * [`program`]: the protocol of validators, renderers, converters and steps;
//! * [`view`]: rendering views, comparing them, installing them;
//! * [`store`]: snapshots on disk, and the views in place;
//! * [`plan`]: what a submission would do, and applying it;
//! * [`pack`]: making a submission from a source list.

pub mod content;
pub mod media;
pub mod name;
pub mod pack;
pub mod plan;
pub mod program;
pub mod schema;
pub mod scratch;
pub mod store;
pub mod submission;
pub mod view;

/// A new identifier for a snapshot: a random UUID (version 4).
pub fn new_id() -> anyhow::Result<String> {
    use std::io::Read;
    let mut bytes = [0u8; 16];
    std::fs::File::open("/dev/urandom")?.read_exact(&mut bytes)?;
    bytes[6] = (bytes[6] & 0x0f) | 0x40;
    bytes[8] = (bytes[8] & 0x3f) | 0x80;
    let hex: String = bytes.iter().map(|byte| format!("{byte:02x}")).collect();
    Ok(format!(
        "{}-{}-{}-{}-{}",
        &hex[0..8],
        &hex[8..12],
        &hex[12..16],
        &hex[16..20],
        &hex[20..32]
    ))
}