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
use std::fmt::Display;

mod errors;
mod node;
pub use node::*;

/// Trait for inserting a value into a Cap'n'proto result builder.
///
/// This is used to map internal types to Cap'n'proto types.
pub trait ResultBuilder<T>: Sized {
    type Output;

    /// Insert a value into the result builder
    ///
    /// # Arguments
    ///
    /// * `value` - The value to insert.
    fn insert(self, value: T) -> Result<Self::Output, capnp::Error>;
}

#[derive(Debug)]
pub enum ParserError {
    InvalidNode,
    InvalidIp(String),
}

impl Display for ParserError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::InvalidNode => write!(f, "Invalid node"),
            Self::InvalidIp(msg) => write!(f, "{}", msg),
        }
    }
}