Struct bpaf::Doc

source ·
pub struct Doc { /* private fields */ }
Expand description

String with styled segments.

You can add style information to generated documentation and help messages For simpliest possible results you can also pass a string slice in all the places that require impl Into<Doc>

Implementations§

source§

impl Doc

source

pub fn monochrome(&self, full: bool) -> String

Render a monochrome version of the document

full indicates if full message should be rendered, this makes difference for rendered help message, otherwise you can pass true.

source§

impl Doc

source

pub fn render_markdown(&self, full: bool) -> String

Render doc into markdown document, used by documentation sample generator

source§

impl Doc

source

pub fn text(&mut self, text: &str)

Append a fragment of plain text to Doc

See Doc for usage examples

Examples found in repository?
examples/customize_help.rs (line 17)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let opt = short('d')
        .help("Release the dragon")
        .switch()
        .to_options()
        .descr("I am a program and I do things")
        .header("Sometimes they even work.")
        .footer("Beware `-d`, dragons be here")
        .with_usage(|doc| {
            let mut u = Doc::default();
            u.emphasis("You can call it with following flags:");
            u.text(" ");
            u.doc(&doc);
            u
        })
        .run();

    println!("{:?}", opt);
}
source

pub fn literal(&mut self, text: &str)

Append a fragment of literal text to Doc

See Doc for usage examples

source

pub fn emphasis(&mut self, text: &str)

Append a fragment of text with emphasis to Doc

See Doc for usage examples

Examples found in repository?
examples/customize_help.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let opt = short('d')
        .help("Release the dragon")
        .switch()
        .to_options()
        .descr("I am a program and I do things")
        .header("Sometimes they even work.")
        .footer("Beware `-d`, dragons be here")
        .with_usage(|doc| {
            let mut u = Doc::default();
            u.emphasis("You can call it with following flags:");
            u.text(" ");
            u.doc(&doc);
            u
        })
        .run();

    println!("{:?}", opt);
}
source

pub fn invalid(&mut self, text: &str)

Append a fragment of unexpected user input to Doc

See Doc for usage examples

source

pub fn meta(&mut self, meta: MetaInfo<'_>, for_usage: bool)

Append a fragment of parser metadata to Doc

See Doc for usage examples

source

pub fn doc(&mut self, buf: &Doc)

Append a Doc to Doc

See Doc for usage examples

Examples found in repository?
examples/customize_help.rs (line 18)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let opt = short('d')
        .help("Release the dragon")
        .switch()
        .to_options()
        .descr("I am a program and I do things")
        .header("Sometimes they even work.")
        .footer("Beware `-d`, dragons be here")
        .with_usage(|doc| {
            let mut u = Doc::default();
            u.emphasis("You can call it with following flags:");
            u.text(" ");
            u.doc(&doc);
            u
        })
        .run();

    println!("{:?}", opt);
}
source

pub fn em_doc(&mut self, buf: &Doc)

Append a Doc to Doc for plaintext documents try to format first line as a help section header

Trait Implementations§

source§

impl Clone for Doc

source§

fn clone(&self) -> Doc

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Doc

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Doc

source§

fn default() -> Doc

Returns the “default value” for a type. Read more
source§

impl Display for Doc

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&[(&str, Style)]> for Doc

source§

fn from(val: &[(&str, Style)]) -> Self

Converts to this type from the input type.
source§

impl<const N: usize> From<&'static [(&'static str, Style); N]> for Doc

source§

fn from(val: &'static [(&'static str, Style); N]) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Doc

source§

fn from(value: &str) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Doc

§

impl RefUnwindSafe for Doc

§

impl Send for Doc

§

impl Sync for Doc

§

impl Unpin for Doc

§

impl UnwindSafe for Doc

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.