Enum aopt_help::error::Error

source ·
pub enum Error {
    Null,
    InvalidBlockName(String),
    DuplicatedBlockName(String),
    InvalidStoreName(String),
    DuplicatedStoreName(String),
    DuplicatedCommandName(String),
    Error(String),
}

Variants§

§

Null

§

InvalidBlockName(String)

§

DuplicatedBlockName(String)

§

InvalidStoreName(String)

§

DuplicatedStoreName(String)

§

DuplicatedCommandName(String)

§

Error(String)

Implementations§

Examples found in repository?
src/lib.rs (line 264)
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
    pub fn display(&mut self, show_global: bool) -> Result<()> {
        let policy = DefaultAppPolicy::new(vec![], show_global);
        let help = policy.format(self).ok_or_else(|| {
            Error::raise("Can not format app help with DefaultAppPolicy".to_string())
        })?;

        writeln!(&mut self.writer, "{}", help)
            .map_err(|e| Error::raise(format!("Can not write to handler: {:?}", e)))
    }

    pub fn display_with<P>(&mut self, policy: P) -> Result<()>
    where
        P: HelpPolicy<'a, Self>,
    {
        let help = policy
            .format(self)
            .ok_or_else(|| Error::raise("Can not format app help with given policy".to_string()))?;

        writeln!(&mut self.writer, "{}", help)
            .map_err(|e| Error::raise(format!("Can not write to handler: {:?}", e)))
    }

    pub fn display_cmd<S>(&mut self, cmd: S) -> Result<()>
    where
        S: Into<Cow<'a, str>>,
    {
        let name = cmd.into();
        let cmd = self.cmds.iter().find(|v| v.name() == name).ok_or_else(|| {
            Error::raise(format!("Can not format help of {name} with DefaultPolicy"))
        })?;
        let policy = DefaultPolicy::new(self.name(), self.style.clone(), vec![], true);
        let help = policy.format(cmd).ok_or_else(|| todo!())?;

        writeln!(&mut self.writer, "{}", help)
            .map_err(|e| Error::raise(format!("Can not write to handler: {:?}", e)))
    }

    pub fn display_cmd_with<S, P>(&mut self, cmd: S, policy: P) -> Result<()>
    where
        P: HelpPolicy<'a, Command<'a>>,
        S: Into<Cow<'a, str>>,
    {
        let name = cmd.into();
        let cmd = self.cmds.iter().find(|v| v.name() == name).ok_or_else(|| {
            Error::raise(format!("Can not format help of {name} with given policy"))
        })?;
        let help = policy.format(cmd).ok_or_else(|| todo!())?;

        writeln!(&mut self.writer, "{}", help)
            .map_err(|e| Error::raise(format!("Can not write to handler: {:?}", e)))
    }
Examples found in repository?
src/error.rs (line 30)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.display())
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        None
    }

    fn cause(&self) -> Option<&dyn std::error::Error> {
        self.source()
    }
}

impl Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.display())
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
The lower-level source of this error, if any. Read more
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
👎Deprecated since 1.42.0: use the Display impl or to_string()
🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

🔬This is a nightly-only experimental API. (provide_any)
Data providers should implement this method to provide all values they are able to provide by using demand. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.