I have a struct of arguments and then try to do some basic logic on the output and assign the argument value to a variable upon certain conditions:
struct Args {
name: String,
from: String,
}
fn main() {
let args = Args {
name: "Jane".to_string(),
from: "Jane Doe <jane@example.com>".to_string(),
};
let default_username: String = "Sendmail Wrapper".to_owned();
let username = if args.name != default_username {
args.name.clone();
};
let username = if (args.name == default_username) && (args.from != default_username) {
args.from.clone();
};
println!("{}",username);
}
When running the code above I get and error from Rust:
error[E0277]: `()` doesn't implement `std::fmt::Display`
--> src/main.rs:73:19
|
73 | println!("{}",username);
| ^^^^^^^^ `()` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
If I use println!("{:?}",username); or println!("{:#?}",username); I simply get () printed.
How do I assign the struct variables to the username variable?