use std::{error, fmt};
use crate::buffer;
pub mod inline;
mod owned;
pub(in crate::buffer) mod raw;
pub mod shared;
pub use owned::Owned;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BuildError<E> {
Capacity(buffer::CapacityError),
Build(E),
LengthMismatch { expected: usize, actual: usize },
}
impl<E: fmt::Display> fmt::Display for BuildError<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Capacity(error) => error.fmt(f),
Self::Build(error) => error.fmt(f),
Self::LengthMismatch { expected, actual } => {
write!(
f,
"exact buffer length mismatch: expected {expected}, wrote {actual}"
)
}
}
}
}
impl<E> error::Error for BuildError<E>
where
E: error::Error + 'static,
{
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::Capacity(error) => Some(error),
Self::Build(error) => Some(error),
Self::LengthMismatch { .. } => None,
}
}
}