Declaring a struct for configuration

We have now imported all the necessary dependencies and can declare our configuration file structure. Add the Config struct to your code:

#[derive(Deserialize)]
struct Config {
address: SocketAddr,
}

This struct contains only one field with the address. You can add more, but remember that all fields have to implement the Deserialize trait. The serde crate already has implementations for standard library types. For our types, we have to derive the implementation of Deserialize with the macro of the serde_derive crate.

Everything is ready for us to read the configuration from the file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.93.20