in my rust program, i tried to give a default value to variable "name". However the compile tool give me a panic.
error[E0277]: `Option<std::string::String>` doesn't implement `std::fmt::Display`
--> src/main.rs:6:24
|
6 | #[arg(short, long, default_value_t = Some("shaominghao".to_string()))]
| ^^^^^^^^^^^^^^^ `Option<std::string::String>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Option<std::string::String>`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required because of the requirements on the impl of `ToString` for `Option<std::string::String>`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `oom_monitor` due to previous error
i don't konow why i can't use this default value. Because in the normal case, the varibale's can also be in this
If you give your option type a default value, how is the field ever going to be None? Your option doesn't serve a purpose here, you can make your field be just a String, without the Option.
your replay is very good. If i give a default value, it would can't be none. I can understand your means. But i can't understand why the compile tools give me the error about "format display". Because it could be display.