#![warn(missing_docs, clippy::missing_panics_doc, clippy::missing_errors_doc)]
#![deny(missing_debug_implementations, unsafe_op_in_unsafe_fn)]
pub mod full;
pub use full::Snaplog;
pub mod scoped;
pub use scoped::AsThinScoped;
pub use scoped::AsThinScopedMut;
pub use scoped::IntoScoped;
pub use scoped::Snaplog as ScopedSnaplog;
const INVARIANT_UNWRAP: &str = "must have at least one element";
#[derive(Debug, Clone, Copy)]
pub enum Select {
Initial,
At(usize),
Current,
}
impl Select {
fn index_into<'s, T>(&self, slice: &'s [T]) -> &'s T {
match self {
Select::Initial => slice.first().expect(INVARIANT_UNWRAP),
Select::At(idx) => &slice[*idx],
Select::Current => slice.last().expect(INVARIANT_UNWRAP),
}
}
fn index_into_mut<'s, T>(&self, slice: &'s mut [T]) -> &'s mut T {
match self {
Select::Initial => slice.first_mut().expect(INVARIANT_UNWRAP),
Select::At(idx) => &mut slice[*idx],
Select::Current => slice.last_mut().expect(INVARIANT_UNWRAP),
}
}
fn index_into_remove<T>(&self, slice: &mut Vec<T>) -> T {
match self {
Select::Initial => slice.swap_remove(0),
Select::At(idx) => slice.swap_remove(*idx),
Select::Current => slice.pop().expect(INVARIANT_UNWRAP),
}
}
}
pub struct EmptyHistoryError(());
impl std::fmt::Debug for EmptyHistoryError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EmptyHistoryError").finish()
}
}
impl std::fmt::Display for EmptyHistoryError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("the given history was empty but at least one element is required")
}
}
impl std::error::Error for EmptyHistoryError {}