January 2019
Intermediate to advanced
520 pages
14h 32m
English
Our server has four sources of address settings:
We have to join these in this order. It's simple to implement this using a set of options and using the or method to set a value if the option doesn't contain anything. Use the following code to get address values from all of the sources:
let addr = matches.value_of("address") .map(|s| s.to_owned()) .or(env::var("ADDRESS").ok()) .and_then(|addr| addr.parse().ok()) .or(config.map(|config| config.address)) .or_else(|| Some(([127, 0, 0, 1], 8080).into())) .unwrap();
At first, this code takes a value from the --address command-line parameter. If it doesn't contain any ...
Read now
Unlock full access