#Code review for a basic console to-do application
1 messages · Page 1 of 1 (latest)
yes, you would have to implement Error
Yeah that answer looks about right. You would not have a string/str in the struct itself. Things like making strings or descriptions of the error should be done in the Display impl
because it's basically impossible to properly handle string errors
Also take a look at how https://doc.rust-lang.org/std/num/struct.ParseIntError.html is implemented
An error which can be returned when parsing an integer.
Because, in a real application, you would end up writing shit like rust match error{ "string cannot be coerced to integer" => ... "index out of bounds" => ... ... } and it would be impossible to statically ensure you handled all errors
or for that matter, that nobody is making typos
and if someone changed the message or added a new error kind, this would all break
an error type has none of these concerns, because all of the above will be a compile error
had another look. the error struct is about what I'd write myself, but you don't need the to_string() in there. You can simply just return &'static str or inline them, which you would need to do if you want to do actual string formatting using format! or write!
// I don't want these to be so long but rust places // new lines automatically
you can do rust "i am a very big \ string"
Also, avoid methods like rust impl ToDoItem { pub fn print(&self) { Just implement Display instead