#Code review for a basic console to-do application

1 messages · Page 1 of 1 (latest)

edgy thicket
#

a function like parse_to_int() should really return a Result<_, MyErrorType> (read: don't use string as an error variant)

edgy thicket
#

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

#

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

edgy thicket
#

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