jeff/
lib.rs

1//! The data model of the jeff representation.
2//!
3//! This crate defines data structures for zero-copy decoding of jeff files.
4mod capnp;
5mod jeff;
6
7#[cfg(test)]
8mod test;
9
10pub mod reader;
11pub mod types;
12pub use jeff::Jeff;
13
14// The capnp-generated code is re-exported here, but in general it should not be
15// used directly.
16//
17// No semver guarantees are provided for this module.
18#[doc(hidden)]
19pub use capnp::jeff_capnp;
20
21use derive_more::derive::{Display, Error, From};
22
23/// Latest version of the jeff schema.
24pub const SCHEMA_VERSION: u32 = 0;
25
26/// Errors that can occur when processing a jeff file.
27#[derive(Debug, Display, From, Error)]
28#[non_exhaustive]
29pub enum JeffError {
30    /// The jeff file is invalid.
31    #[display("Invalid jeff file: {_0}")]
32    InvalidFile(::capnp::Error),
33    /// Invalid schema version.
34    #[display("Invalid schema version: {v}. Expected {}", Jeff::VERSION)]
35    InvalidVersion {
36        /// The invalid schema version.
37        v: u32,
38    },
39    /// Error while reading the internal structure.
40    ReadError(reader::ReadError),
41}
42
43/// Direction of a port.
44#[derive(Clone, Copy, Debug, Display, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
45pub enum Direction {
46    /// Input to a node.
47    #[default]
48    Incoming = 0,
49    /// Output from a node.
50    Outgoing = 1,
51}
52
53impl Direction {
54    /// Incoming and outgoing directions.
55    pub const BOTH: [Direction; 2] = [Direction::Incoming, Direction::Outgoing];
56
57    /// Returns the opposite direction.
58    #[inline(always)]
59    pub fn reverse(self) -> Direction {
60        match self {
61            Direction::Incoming => Direction::Outgoing,
62            Direction::Outgoing => Direction::Incoming,
63        }
64    }
65}