Skip to content

Commit

Permalink
Remove questionable unsafe impl Send
Browse files Browse the repository at this point in the history
API breakage as we now explicitly state `History + Send + Sync`
  • Loading branch information
sholderbach committed Dec 21, 2024
1 parent 1800dcd commit 319a44f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/completion/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const SELECTION_CHAR: char = '!';

// The HistoryCompleter is created just before updating the menu
// It pulls data from the object that contains access to the History
pub(crate) struct HistoryCompleter<'menu>(&'menu dyn History);

// Safe to implement Send since the HistoryCompleter should only be used when
// updating the menu and that must happen in the same thread
unsafe impl Send for HistoryCompleter<'_> {}
pub(crate) struct HistoryCompleter<'menu>(&'menu (dyn History + Send + Sync));

fn search_unique(
completer: &HistoryCompleter,
Expand Down Expand Up @@ -48,7 +44,7 @@ impl Completer for HistoryCompleter<'_> {
}

impl<'menu> HistoryCompleter<'menu> {
pub fn new(history: &'menu dyn History) -> Self {
pub fn new(history: &'menu (dyn History + Send + Sync)) -> Self {
Self(history)
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct Reedline {
editor: Editor,

// History
history: Box<dyn History>,
history: Box<dyn History + Send + Sync>,
history_cursor: HistoryCursor,
history_session_id: Option<HistorySessionId>,
// none if history doesn't support this
Expand Down Expand Up @@ -420,7 +420,7 @@ impl Reedline {
/// .with_history(history);
/// ```
#[must_use]
pub fn with_history(mut self, history: Box<dyn History>) -> Self {
pub fn with_history(mut self, history: Box<dyn History + Send + Sync>) -> Self {
self.history = history;
self
}
Expand Down
6 changes: 3 additions & 3 deletions src/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl ReedlineMenu {
values_updated: bool,
editor: &mut Editor,
completer: &mut dyn Completer,
history: &dyn History,
history: &(dyn History + Send + Sync),
) -> bool {
match self {
Self::EngineCompleter(menu) => {
Expand All @@ -328,7 +328,7 @@ impl ReedlineMenu {
&mut self,
editor: &mut Editor,
completer: &mut dyn Completer,
history: &dyn History,
history: &(dyn History + Send + Sync),
) {
match self {
Self::EngineCompleter(menu) => menu.update_values(editor, completer),
Expand All @@ -349,7 +349,7 @@ impl ReedlineMenu {
&mut self,
editor: &mut Editor,
completer: &mut dyn Completer,
history: &dyn History,
history: &(dyn History + Send + Sync),
painter: &Painter,
) {
match self {
Expand Down

0 comments on commit 319a44f

Please sign in to comment.