Skip to main content

vs_protocol/
lib.rs

1//! Wire-protocol encoder/decoder for vibesurfer.
2//!
3//! `vs-protocol` is the shared specification of the line-oriented wire
4//! format documented in `docs/PROTOCOL.md` at the workspace root. The
5//! daemon and the CLI both link this crate; the daemon emits, the CLI
6//! parses (and vice-versa for requests).
7//!
8//! # Layout
9//!
10//! - [`codes`] — short codes ([`Role`], [`Op`], [`ErrorCode`],
11//!   [`WarningCode`]) with `Display` and `FromStr` implementations.
12//! - [`tree`] — in-memory [`Tree`] / [`Node`] / [`Ref`] and the
13//!   indented full-tree wire format.
14//! - [`delta`] — [`DeltaOp`] with encode/parse/[`apply`]/[`diff`].
15//! - [`envelope`] — [`StateToken`], [`Warning`], [`Envelope`], and
16//!   [`ResponseHead`].
17//! - [`request`] — [`Request`] line.
18//! - [`error::ParseError`] — every fallible parser returns this.
19
20#![forbid(unsafe_code)]
21
22pub mod codes;
23pub mod delta;
24pub mod envelope;
25pub mod error;
26pub mod request;
27mod tokenize;
28pub mod tree;
29
30pub use codes::{ErrorCode, Op, Role, UnknownCode, WarningCode};
31pub use delta::{apply, diff, DeltaOp};
32pub use envelope::{Envelope, ResponseHead, StateToken, Warning};
33pub use error::{ParseError, Result};
34pub use request::Request;
35pub use tree::{Node, Ref, Tree};
36
37/// Returns the crate version (matches the workspace version).
38#[must_use]
39pub fn version() -> &'static str {
40    env!("CARGO_PKG_VERSION")
41}
42
43#[cfg(test)]
44mod tests {
45    use super::version;
46
47    #[test]
48    fn version_matches_cargo_pkg_version() {
49        assert_eq!(version(), env!("CARGO_PKG_VERSION"));
50    }
51}