diff --git a/src/backing/containers/mod.rs b/src/backing/containers/mod.rs index 74cfd32..992fa05 100644 --- a/src/backing/containers/mod.rs +++ b/src/backing/containers/mod.rs @@ -1,5 +1,7 @@ mod pair; mod py_item; +mod sift_result; pub use pair::Pair; pub use py_item::PyItem; +pub use sift_result::{SiftError, SiftResult}; diff --git a/src/backing/containers/sift_result.rs b/src/backing/containers/sift_result.rs new file mode 100644 index 0000000..8b1e323 --- /dev/null +++ b/src/backing/containers/sift_result.rs @@ -0,0 +1,26 @@ +use std::fmt::{Display, Formatter, Result as fmtResult}; + +/// Indicates why a sift failed +#[derive(Debug, Clone)] +pub struct SiftError { + /// The index that couldn't be sifted + index: usize, + /// The length of the array + len: usize, +} + +impl SiftError { + /// Instantiates a `SiftError` + pub fn new(index: usize, len: usize) -> Self { + Self { index, len } + } +} + +impl Display for SiftError { + fn fmt(&self, f: &mut Formatter) -> fmtResult { + write!(f, "Could not sift index {} of {}", self.index, self.len) + } +} + +/// Whether a sift operation succeeded +pub type SiftResult = Result<(), SiftError>; diff --git a/src/backing/pure/binary_heap.rs b/src/backing/pure/binary_heap.rs index cd84f18..2b43ec0 100644 --- a/src/backing/pure/binary_heap.rs +++ b/src/backing/pure/binary_heap.rs @@ -1,32 +1,7 @@ -use std::fmt; +use crate::backing::containers::{SiftError, SiftResult}; use super::PureBacking; -/// Indicates why a sift failed -#[derive(Debug, Clone)] -struct SiftError { - /// The index that couldn't be sifted - index: usize, - /// The length of the array - len: usize, -} - -impl SiftError { - /// Instantiates a `SiftError` - fn new(index: usize, len: usize) -> Self { - Self { index, len } - } -} - -impl fmt::Display for SiftError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Could not sift index {} of {}", self.index, self.len) - } -} - -/// Whether a sift operation succeeded -type SiftResult = Result<(), SiftError>; - /// A binary min-heap backed by an array #[derive(Debug)] pub struct BinaryHeap {