From 736798e65a4e7c9f9ff3f54540b69074975ddc4f Mon Sep 17 00:00:00 2001 From: James Pace Date: Fri, 3 Jul 2026 13:40:00 -0400 Subject: [PATCH] Move graph error to its own module. --- src/graph_error.rs | 32 ++++++++++++++++++++++++++++++++ src/lib.rs | 24 ++---------------------- 2 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 src/graph_error.rs diff --git a/src/graph_error.rs b/src/graph_error.rs new file mode 100644 index 0000000..aea6588 --- /dev/null +++ b/src/graph_error.rs @@ -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 {} diff --git a/src/lib.rs b/src/lib.rs index 39bd653..67f9aff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,12 +11,13 @@ #![no_std] extern crate alloc; mod node; +mod graph_error; use alloc::collections::vec_deque::VecDeque; -use alloc::string::{String, ToString}; use alloc::vec; use alloc::vec::Vec; pub use node::*; +pub use graph_error::*; /// A generic graph type holding values connected to other values. /// Values can be added to the graph, but not removed. @@ -145,27 +146,6 @@ impl Graph { } } -#[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)] mod tests { use super::*;