ode_base/ode/
err.rs

1//! err
2//!
3
4use crate::ode::*;
5
6use std::fmt;
7use std::error::Error;
8
9/// for Result<_, Box<dyn Error>> handling
10#[derive(Debug)]
11pub struct ODEError {
12  msg: String
13}
14
15/// for Result<_, Box<dyn Error>> handling
16impl ODEError {
17  /// construct
18  pub fn no_key(k: String) -> ODEError {
19    ODEError{msg: format!("no key [{}] in mbgs", k)}
20  }
21
22  /// construct
23  pub fn no_id(id: dBodyID) -> ODEError {
24    ODEError{msg: format!("no id {:018p} in obgs", id)}
25  }
26
27  /// construct
28  pub fn no_mgm_id(id: dGeomID) -> ODEError {
29    ODEError{msg: format!("no mgm id {:018p} in mgms", id)}
30  }
31}
32
33/// formatter
34impl fmt::Display for ODEError {
35  /// formatter
36  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37    write!(f, "ODEError: {}", self.msg)
38  }
39}
40
41/// &lt;dyn Error&gt; handler
42impl Error for ODEError {
43  /// &lt;dyn Error&gt; handler
44  fn source(&self) -> Option<&(dyn Error + 'static)> {
45    Some(self)
46  }
47}