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§
source§impl Error
impl Error
sourcepub fn raise(msg: String) -> Self
pub fn raise(msg: String) -> Self
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)))
}
sourcepub fn display(&self) -> String
pub fn display(&self) -> String
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§
source§impl Error for Error
impl Error for Error
source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()