Skip to content

Commit

Permalink
improve the Storage trait.
Browse files Browse the repository at this point in the history
- new trait method: `name`.
- update docs.
  • Loading branch information
joseluis committed Jul 26, 2023
1 parent 844d7df commit e5c61c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/mem/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use core::{cmp, fmt, hash, ops};
///
/// # Examples
/// ```
/// use ladata::mem::Direct;
/// use ladata::all::Direct;
///
/// let lac = Direct::new(0_u8);
/// let byte = Direct::new(0_u8);
/// ```
pub struct Direct<T>(pub T);

Expand Down Expand Up @@ -134,21 +134,3 @@ impl<I: Iterator> Iterator for Direct<I> {
// Direct::last(self)
// }
}

// trait Direct {
// type Item;
// fn last(self) -> Option<Self::Item>;
// }
//
// impl<I: Iterator> Direct for Direct<I> {
// type Item = I::Item;
// fn last(self) -> Option<I::Item> {
// #[inline]
// fn some<T>(_: Option<T>, x: T) -> Option<T> {
// Some(x)
// }
//
// self.fold(None, some)
// }
// }
//
17 changes: 17 additions & 0 deletions src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ pub use size::Size;
///
/// ```
pub trait Storage {
/// The stored associated type.
type Stored<T>: ops::DerefMut<Target = T> + From<T>;

/// Returns the static name of the storage implementation.
///
/// This can be useful for debugging.
fn name() -> &'static str;

// MAYBE WAIT https://github.com/rust-lang/rust/issues/80437
// fn unstore(self) -> T;
}

/// A storage type that wraps its data in a [`Box`].
Expand All @@ -77,9 +86,17 @@ pub struct Boxed;
#[cfg_attr(feature = "nightly", doc(cfg(feature = "alloc")))]
impl Storage for Boxed {
type Stored<T> = alloc::boxed::Box<T>;

fn name() -> &'static str {
"Boxed"
}
}

/// A storage type that wraps its data in a [`Direct`].
impl Storage for () {
type Stored<T> = Direct<T>;

fn name() -> &'static str {
"Direct"
}
}

0 comments on commit e5c61c2

Please sign in to comment.