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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* =================================================================================
 File:           fbp_node_error.rs

 Description:    This file contains an Error type for FBP nodes


 History:        RustDev 03/31/2021   Code ported from original rustfbp crate

 Copyright ©  2021 Pesa Switching Systems Inc. All rights reserved.
================================================================================== */

//! # Specific Error Type for FBP nodes
//!
//! Many of the methods for FBP nodes will return a Result.  Some of those Results will
//! contain an error.  The Error type defined here will provide that Error type.
//!

use std::error::Error;
use std::fmt;

/// # FBP Error Type
///
/// An FBP specific Error type
///
#[derive(Debug)]
pub struct NodeError {
    details: String,
}

impl NodeError {
    /// Creates a new NodeError
    ///
    /// # Example
    ///
    /// Basic usage:
    /// ```
    /// use fbp::fbp_node_error::*;
    ///
    /// let a_fbp_error= NodeError::new("Some error message");
    ///
    /// ```
    ///
    pub fn new(msg: &str) -> NodeError {
        NodeError {
            details: msg.to_string(),
        }
    }
}

impl fmt::Display for NodeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.details)
    }
}

impl Error for NodeError {
    fn description(&self) -> &str {
        &self.details
    }
}