Rust crate for easy debug repl?

Does anyone know of a crate that implements a simple "turn key" REPL for your rust program?

I'm not finding much. There is evcxr, but that is a REPL for rust itself. Which is not what I'm looking for. And there are various crates like parsers and line editing that can form building blocks if you want to build a full blown shell.

But that isn't what I'm looking for. I'm not trying to build a shell. I don't want to go yak shaving further than I already am.

I have a tool that I want to add a debug REPL for that will be useful during development (the final UI will be different). I just want a turn key solution for basic line editing and maybe history, where I provide "here is a list of my commands". Tab completion etc would be a nice bonus, but isn't required.

If there isn't anything that exactly matches I'm also interested in what building blocks would be the closest to working out of the box, for line-editing+history (no need for persistent history) and a simple parser of the commands (ideally something derive-like, similar to how clap works for command line parsing).

EDIT: Also I'm writing async code, so that is also a consideration.

I'm unclear on exactly what you're after. The line "I just want a turn key solution for basic line editing and maybe history" makes it sound like you'd mainly want just a readline-like library like either rustyline or (depending on where the asyncness comes in) rustyline-async, but you also say you don't want "various crates like ... line editing that can form building blocks". Is the problem with those crates that you still have to implement the command-parsing separately? I'm not aware of anything that both does readline-style input and parses the commands for you. How complex are the commands you want to implement?

1 Like

Ah, rustyline-async did not come up in my searches, (rustyline did). Thanks for that.

What I meant is, I'd ideally like something like:

#[derive(SomeDerive)]
enum Commands {
  TweakThing { ... },
  DoOtherThing { ... }.
  Exit
}

async fn run_shell() {
    let repl = Repl<Command>::new();
    loop {
        let user_command = repl.prompt().await;
        match user_command {
            // ...
        }
    }
}

I.e. the library handles parsing, line editing, etc all in one. Building blocks (e.g. rustyline-async + something for the parser) would be my second choice. But I don't want to write a full blown winnow/nom/chumsky/etc parser (I have done that in the past, it takes a lot of time).

The commands are simple. I do need quote-handling though. Something like: send-json '{"foo": "bar spaces" }' would be nicer than send-json "{\"foo\": \"bar spaces\" }" though (so shell-style quote handling).

Finally found something after having given up and starting to implement something myself:

I have not (yet) tried it out. Also it doesn't have a lot of downloads or users, so a quite in depth code review will be required. Might be better to just take inspiration from how it does it.