Move graph error to its own module.
This commit is contained in:
parent
f5b0a710e0
commit
736798e65a
|
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// Copyright 2023 James Pace
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
//
|
||||||
|
// This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
// defined by the Mozilla Public License, v. 2.0.
|
||||||
|
//
|
||||||
|
use alloc::string::{String, ToString};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct GraphError {
|
||||||
|
pub msg: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GraphError {
|
||||||
|
pub fn from_msg(msg: &str) -> Self {
|
||||||
|
GraphError {
|
||||||
|
msg: msg.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Display for GraphError {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
|
write!(f, "Error manipulating graph: {}", self.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::error::Error for GraphError {}
|
||||||
24
src/lib.rs
24
src/lib.rs
|
|
@ -11,12 +11,13 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
mod node;
|
mod node;
|
||||||
|
mod graph_error;
|
||||||
|
|
||||||
use alloc::collections::vec_deque::VecDeque;
|
use alloc::collections::vec_deque::VecDeque;
|
||||||
use alloc::string::{String, ToString};
|
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
pub use node::*;
|
pub use node::*;
|
||||||
|
pub use graph_error::*;
|
||||||
|
|
||||||
/// A generic graph type holding values connected to other values.
|
/// A generic graph type holding values connected to other values.
|
||||||
/// Values can be added to the graph, but not removed.
|
/// Values can be added to the graph, but not removed.
|
||||||
|
|
@ -145,27 +146,6 @@ impl<NodeValueT: NodeValue> Graph<NodeValueT> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct GraphError {
|
|
||||||
pub msg: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GraphError {
|
|
||||||
pub fn from_msg(msg: &str) -> Self {
|
|
||||||
GraphError {
|
|
||||||
msg: msg.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl core::fmt::Display for GraphError {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
|
||||||
write!(f, "Error manipulating graph: {}", self.msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl core::error::Error for GraphError {}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue