diff --git a/src/history.rs b/src/history.rs index d7457bd..eeae588 100644 --- a/src/history.rs +++ b/src/history.rs @@ -10,7 +10,7 @@ pub use checkpoint::Checkpoint; pub use display::Display; pub use queue::Queue; -use crate::socket::{Nop, Signal, Slot}; +use crate::socket::{Signal, Slot}; use crate::{At, Edit, Entry, Record}; use alloc::collections::{BTreeMap, VecDeque}; use alloc::string::{String, ToString}; @@ -52,7 +52,7 @@ use serde::{Deserialize, Serialize}; /// ``` #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug)] -pub struct History { +pub struct History { root: usize, next: usize, saved: Option, diff --git a/src/history/builder.rs b/src/history/builder.rs index 8162b7b..4db6fc8 100644 --- a/src/history/builder.rs +++ b/src/history/builder.rs @@ -1,5 +1,5 @@ use crate::record::Builder as RecordBuilder; -use crate::{History, Nop}; +use crate::History; /// Builder for a [`History`]. /// @@ -18,7 +18,7 @@ use crate::{History, Nop}; /// # } /// ``` #[derive(Debug)] -pub struct Builder(RecordBuilder); +pub struct Builder(RecordBuilder); impl Builder { /// Sets the capacity for the history. diff --git a/src/lib.rs b/src/lib.rs index 4e83df8..8fd4a9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ pub use join::Join; #[cfg(feature = "alloc")] pub use record::Record; #[cfg(feature = "alloc")] -pub use socket::{Nop, Signal, Slot}; +pub use socket::{Signal, Slot}; /// Base functionality for all edit commands. pub trait Edit { diff --git a/src/record.rs b/src/record.rs index 4ac1a3a..bb39ffe 100644 --- a/src/record.rs +++ b/src/record.rs @@ -10,7 +10,7 @@ pub use checkpoint::Checkpoint; pub use display::Display; pub use queue::Queue; -use crate::socket::{Nop, Slot, Socket}; +use crate::socket::{Slot, Socket}; use crate::{Edit, Entry, History, Merged, Signal}; use alloc::collections::VecDeque; use alloc::string::{String, ToString}; @@ -59,7 +59,7 @@ use serde::{Deserialize, Serialize}; /// ``` #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug)] -pub struct Record { +pub struct Record { pub(crate) entries: VecDeque>, pub(crate) limit: NonZeroUsize, pub(crate) index: usize, diff --git a/src/record/builder.rs b/src/record/builder.rs index 165c00e..ed6c8bd 100644 --- a/src/record/builder.rs +++ b/src/record/builder.rs @@ -1,5 +1,5 @@ use super::Socket; -use crate::{Nop, Record}; +use crate::Record; use alloc::collections::VecDeque; use core::marker::PhantomData; use core::num::NonZeroUsize; @@ -21,7 +21,7 @@ use core::num::NonZeroUsize; /// # } /// ``` #[derive(Debug)] -pub struct Builder { +pub struct Builder { capacity: usize, limit: NonZeroUsize, saved: bool, diff --git a/src/socket.rs b/src/socket.rs index 0dad9e9..59f67f9 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -45,6 +45,20 @@ impl Socket { } } +/// The `Signal` describes the state change done to the data structures. +/// +/// See [`Slot`] for more information. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub enum Signal { + /// Says if the structures can undo. + Undo(bool), + /// Says if the structures can redo. + Redo(bool), + /// Says if the target is in a saved state. + Saved(bool), +} + /// Use this to handle signals emitted. /// /// This allows you to trigger events on certain state changes. @@ -80,6 +94,10 @@ pub trait Slot { fn on_emit(&mut self, signal: Signal); } +impl Slot for () { + fn on_emit(&mut self, _: Signal) {} +} + impl Slot for F { fn on_emit(&mut self, signal: Signal) { self(signal) @@ -99,26 +117,3 @@ impl Slot for SyncSender { self.send(signal).ok(); } } - -/// The `Signal` describes the state change done to the data structures. -/// -/// See [`Slot`] for more information. -#[derive(Clone, Debug, PartialEq)] -#[non_exhaustive] -pub enum Signal { - /// Says if the structures can undo. - Undo(bool), - /// Says if the structures can redo. - Redo(bool), - /// Says if the target is in a saved state. - Saved(bool), -} - -/// Default [`Slot`] that does nothing. -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] -pub struct Nop; - -impl Slot for Nop { - fn on_emit(&mut self, _: Signal) {} -}