| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#; |
| 2 | |
| 3 | /// An error around some option-setting, and the reason. |
| 4 | /// |
| 5 | /// These are meant to potentially be user-facing (e.g. explain |
| 6 | /// why it's broken and what to fix), and as so treat it as such! |
| 7 | /// |
| 8 | /// For stylistic and consistency reasons, use _single quotes_ (e.g. `'bad'`) |
| 9 | /// for highlighting error values. You can use (".*`.+`.*") as a regex to check |
| 10 | /// for this. |
| 11 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 12 | pub enum OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError# { |
| 13 | Configrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Config#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>), |
| 14 | Argumentrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Argument#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>), |
| 15 | Otherrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Other#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>), |
| 16 | } |
| 17 | |
| 18 | impl OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError# { |
| 19 | /// Create a new [`OptionError::Config`]. |
| 20 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn configrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError]config().<R: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>>>(reason: R) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError] { |
| 21 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Configrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Config#(reason.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()) |
| 22 | } |
| 23 | |
| 24 | /// Create a new [`OptionError::Config`] for an invalid value. |
| 25 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn invalid_config_valuerust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError]invalid_config_value().(value: &str) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError] { |
| 26 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Configrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Config#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 27 | "'{value}' was set with an invalid value, please update it in your config file." |
| 28 | ))) |
| 29 | } |
| 30 | |
| 31 | /// Create a new [`OptionError::Argument`]. |
| 32 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn argrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError]arg().<R: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>>>(reason: R) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError] { |
| 33 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Argumentrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Argument#(reason.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()) |
| 34 | } |
| 35 | |
| 36 | /// Create a new [`OptionError::Argument`] for an invalid value. |
| 37 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn invalid_arg_valuerust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError]invalid_arg_value().(value: &str) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError] { |
| 38 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Argumentrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Argument#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 39 | "'--{value}' was set with an invalid value, please update your arguments." |
| 40 | ))) |
| 41 | } |
| 42 | |
| 43 | /// Create a new [`OptionError::Other`]. |
| 44 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn otherrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError]other().<R: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>>>(reason: R) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError] { |
| 45 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Otherrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Other#(reason.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) type OptionResultrust-analyzer cargo bottom 0.14.9 options/error/OptionResult#<T> = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#>; |
| 50 | |
| 51 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError# { |
| 52 | fn fmtrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 53 | match self { |
| 54 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Configrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Config#(reason) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Configuration file error: {reason}"), |
| 55 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Argumentrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Argument#(reason) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Argument error: {reason}"), |
| 56 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Otherrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Other#(reason) => { |
| 57 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error with the config file or the arguments: {reason}") |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError# {} |
| 64 | |
| 65 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::Errorrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/error/Error#> for OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError# { |
| 66 | fn fromrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError][`From<toml_edit::de::Error>`]from().(err: toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::Errorrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/error/Error#) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError][`From<toml_edit::de::Error>`] { |
| 67 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Configrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Config#(err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError# { |
| 72 | fn fromrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError][`From<std::io::Error>`]from().(err: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> Selfrust-analyzer cargo bottom 0.14.9 options/error/impl#[OptionError][`From<std::io::Error>`] { |
| 73 | OptionErrorrust-analyzer cargo bottom 0.14.9 options/error/OptionError#::Otherrust-analyzer cargo bottom 0.14.9 options/error/OptionError#Other#(err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 74 | } |
| 75 | } |