Struct repl_rs::Repl

source ·
pub struct Repl<Context, E: Display> { /* private fields */ }
Expand description

Main REPL struct

Implementations§

source§

impl<Context, E> Repl<Context, E>where E: Display + From<Error>,

source

pub fn new(context: Context) -> Self

Create a new Repl with the given context’s initial value.

Examples found in repository?
examples/custom_error.rs (line 41)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional examples
examples/custom_prompt.rs (line 22)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
examples/with_context.rs (line 33)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
examples/no_context.rs (line 23)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("add", add)
                .with_parameter(Parameter::new("first").set_required(true)?)?
                .with_parameter(Parameter::new("second").set_required(true)?)?
                .with_help("Add two numbers together"),
        )
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
source

pub fn with_name(self, name: &str) -> Self

Give your Repl a name. This is used in the help summary for the Repl.

Examples found in repository?
examples/custom_error.rs (line 42)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional examples
examples/custom_prompt.rs (line 23)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
examples/with_context.rs (line 34)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
examples/no_context.rs (line 24)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("add", add)
                .with_parameter(Parameter::new("first").set_required(true)?)?
                .with_parameter(Parameter::new("second").set_required(true)?)?
                .with_help("Add two numbers together"),
        )
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
source

pub fn with_version(self, version: &str) -> Self

Give your Repl a version. This is used in the help summary for the Repl.

Examples found in repository?
examples/custom_error.rs (line 43)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional examples
examples/custom_prompt.rs (line 25)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
examples/with_context.rs (line 35)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
examples/no_context.rs (line 25)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("add", add)
                .with_parameter(Parameter::new("first").set_required(true)?)?
                .with_parameter(Parameter::new("second").set_required(true)?)?
                .with_help("Add two numbers together"),
        )
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
source

pub fn with_description(self, description: &str) -> Self

Give your Repl a description. This is used in the help summary for the Repl.

Examples found in repository?
examples/custom_error.rs (line 44)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional examples
examples/custom_prompt.rs (line 26)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
examples/with_context.rs (line 36)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
examples/no_context.rs (line 26)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("add", add)
                .with_parameter(Parameter::new("first").set_required(true)?)?
                .with_parameter(Parameter::new("second").set_required(true)?)?
                .with_help("Add two numbers together"),
        )
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
source

pub fn with_prompt(self, prompt: &'static dyn Display) -> Self

Give your Repl a custom prompt. The default prompt is the Repl name, followed by a >, all in green, followed by a space.

Examples found in repository?
examples/custom_prompt.rs (line 24)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
source

pub fn with_help_viewer<V: 'static + HelpViewer>(self, help_viewer: V) -> Self

Pass in a custom help viewer

source

pub fn with_error_handler( self, handler: fn(error: E, repl: &Repl<Context, E>) -> Result<()> ) -> Self

Pass in a custom error handler. This is really only for testing - the default error handler simply prints the error to stderr and then returns

source

pub fn use_completion(self, value: bool) -> Self

Set whether to use command completion when tab is hit. Defaults to false.

Examples found in repository?
examples/with_context.rs (line 37)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
source

pub fn add_command(self, command: Command<Context, E>) -> Self

Add a command to your REPL

Examples found in repository?
examples/custom_error.rs (line 45)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional examples
examples/custom_prompt.rs (lines 27-31)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
examples/with_context.rs (lines 38-42)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
examples/no_context.rs (lines 27-32)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("add", add)
                .with_parameter(Parameter::new("first").set_required(true)?)?
                .with_parameter(Parameter::new("second").set_required(true)?)?
                .with_help("Add two numbers together"),
        )
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
source

pub fn run(&mut self) -> Result<()>

Examples found in repository?
examples/custom_error.rs (line 46)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional examples
examples/custom_prompt.rs (line 32)
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_prompt(&CustomPrompt)
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}
examples/with_context.rs (line 48)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> Result<()> {
    let mut repl = Repl::new(Context::default())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .use_completion(true)
        .add_command(
            Command::new("append", append)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Append name to end of list"),
        )
        .add_command(
            Command::new("prepend", prepend)
                .with_parameter(Parameter::new("name").set_required(true)?)?
                .with_help("Prepend name to front of list"),
        );
    repl.run()
}
examples/no_context.rs (line 38)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() -> Result<()> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(
            Command::new("add", add)
                .with_parameter(Parameter::new("first").set_required(true)?)?
                .with_parameter(Parameter::new("second").set_required(true)?)?
                .with_help("Add two numbers together"),
        )
        .add_command(
            Command::new("hello", hello)
                .with_parameter(Parameter::new("who").set_required(true)?)?
                .with_help("Greetings!"),
        );
    repl.run()
}

Auto Trait Implementations§

§

impl<Context, E> !RefUnwindSafe for Repl<Context, E>

§

impl<Context, E> !Send for Repl<Context, E>

§

impl<Context, E> !Sync for Repl<Context, E>

§

impl<Context, E> Unpin for Repl<Context, E>where Context: Unpin,

§

impl<Context, E> !UnwindSafe for Repl<Context, E>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.