termosaic 0.3.0

Semantic, structured output for human, machine-text, and opaque-byte destinations
Documentation
//! Small semantic atoms used by native components and application documents.

use crate::{Doc, TokenId, tokens};

pub fn text(token: TokenId, value: impl AsRef<str>) -> Doc {
    Doc::token_text(token, value)
}

pub fn identifier(value: impl AsRef<str>) -> Doc {
    text(tokens::ENTITY_IDENTIFIER, value)
}

pub fn path(value: impl AsRef<str>) -> Doc {
    text(tokens::ENTITY_PATH, value)
}

pub fn url(value: impl AsRef<str>) -> Doc {
    text(tokens::ENTITY_URL, value)
}

pub fn revision(value: impl AsRef<str>) -> Doc {
    text(tokens::ENTITY_REVISION, value)
}

pub fn comment(value: impl AsRef<str>) -> Doc {
    text(tokens::TEXT_COMMENT, value)
}

pub fn string(value: impl AsRef<str>) -> Doc {
    Doc::tokens([tokens::DATA, tokens::DATA_STRING], Doc::text(value))
}

pub fn boolean(value: bool) -> Doc {
    Doc::tokens(
        [tokens::DATA, tokens::DATA_BOOLEAN],
        Doc::text(if value { "true" } else { "false" }),
    )
}

pub fn null() -> Doc {
    Doc::tokens([tokens::DATA, tokens::DATA_NULL], Doc::text("null"))
}

pub fn status(token: TokenId, doc: Doc) -> Doc {
    Doc::tokens([tokens::STATUS, token], doc)
}

pub fn success(doc: Doc) -> Doc {
    status(tokens::STATUS_SUCCESS, doc)
}

pub fn info(doc: Doc) -> Doc {
    status(tokens::STATUS_INFO, doc)
}

pub fn warning(doc: Doc) -> Doc {
    status(tokens::STATUS_WARNING, doc)
}

pub fn error(doc: Doc) -> Doc {
    status(tokens::STATUS_ERROR, doc)
}