Before we start coding the FTP server, let's talk about how we'll be handling the errors.
In the previous projects, we used the unwrap()
or expect()
methods a lot. These methods are handy for fast prototyping, but when we want to write high-quality software, we should avoid them in most cases. Since we're writing an FTP server, a software that must keep running for a long time, we don't want it to crash because we called unwrap()
and a client sent a bad command. So, we'll do proper error handling.
Since we can get different types of errors and we want to keep track of all of them, we'll create a custom error type. Let's create a new module in which we'll put this new type:
mod error;
Add it to the src/error.rs
file:
use std::io; use std::str::Utf8Error; use std::string::FromUtf8Error; pub enum Error { FromUtf8(FromUtf8Error), Io(io::Error), Msg(String), Utf8(Utf8Error), }
Here, we have an enum representing the different errors that can...