We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
use std::fmt; // Import the `fmt` module. #[derive(Debug)] struct DivideError { details: String } impl DivideError { fn new(msg: &str) -> DivideError { DivideError{details: msg.to_string()} } } impl fmt::Display for DivideError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f,"{}",self.details) } } impl std::error::Error for DivideError { fn description(&self) -> &str { &self.details } } fn divide(a: i32, b: i32) -> Result { if b != 0 { Ok(a / b) } else { Err(DivideError::new("can not devide 0")) } } fn divideWrap() -> Result { let result = divide(10, 5)?; println!("{}", result); Ok(()) } fn main() { divideWrap(); }
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Input your email to receive reset password link, or if you remember your password, you can click