Skip to content

Commit

Permalink
repl: work around Send not available on rustyline::Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Nov 3, 2018
1 parent 5d14757 commit 02b8202
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
extern crate rustyline;

use rustyline::error::ReadlineError::Interrupted;
use rustyline::Editor;

use msg::ErrorKind;
use std::error::Error;
Expand All @@ -13,6 +12,49 @@ use errors::DenoResult;
use std::path::PathBuf;
use std::process::exit;

#[cfg(not(windows))]
use rustyline::Editor;

// Work around the issue that on Windows, `struct Editor` does not implement the
// `Send` trait, because it embeds a windows HANDLE which is a type alias for
// *mut c_void. This value isn't actually a pointer and there's nothing that
// can be mutated through it, so hack around it. TODO: a prettier solution.
#[cfg(windows)]
use std::ops::{Deref, DerefMut};

#[cfg(windows)]
struct Editor<T: rustyline::Helper> {
inner: rustyline::Editor<T>,
}

#[cfg(windows)]
unsafe impl<T: rustyline::Helper> Send for Editor<T> {}

#[cfg(windows)]
impl<T: rustyline::Helper> Editor<T> {
pub fn new() -> Editor<T> {
Editor {
inner: rustyline::Editor::<T>::new(),
}
}
}

#[cfg(windows)]
impl<T: rustyline::Helper> Deref for Editor<T> {
type Target = rustyline::Editor<T>;

fn deref(&self) -> &rustyline::Editor<T> {
&self.inner
}
}

#[cfg(windows)]
impl<T: rustyline::Helper> DerefMut for Editor<T> {
fn deref_mut(&mut self) -> &mut rustyline::Editor<T> {
&mut self.inner
}
}

pub struct DenoRepl {
pub name: String,
editor: Editor<()>,
Expand Down

0 comments on commit 02b8202

Please sign in to comment.