Debian Codegraph @

src/urgency.rs

raw symbols SCIP
1 use craterust-analyzer cargo notify-rust 4.18.0 crate/::errorrust-analyzer cargo notify-rust 4.18.0 error/::ErrorKindrust-analyzer cargo notify-rust 4.18.0 error/ErrorKind#;
2
3 /// Levels of Urgency.
4 ///
5 /// # Specification
6 /// > Developers must use their own judgement when deciding the urgency of a notification. Typically, if the majority of programs are using the same level for a specific type of urgency, other applications should follow them.
7 /// >
8 /// > For low and normal urgencies, server implementations may display the notifications how they choose. They should, however, have a sane expiration timeout dependent on the urgency level.
9 /// >
10 /// > **Critical notifications should not automatically expire**, as they are things that the user will most likely want to know about. They should only be closed when the user dismisses them, for example, by clicking on the notification.
11 ///
12 /// <cite> — see [Galago](http://www.galago-project.org/specs/notification/0.9/x320.html) or [Gnome](https://developer.gnome.org/notification-spec/#urgency-levels) specification.</cite>
13 ///
14 /// # Example
15 /// ```no_run
16 /// # use notify_rust::*;
17 /// # fn _doc() -> Result<(), Box<dyn std::error::Error>> {
18 /// Notification::new()
19 /// .summary("oh no")
20 /// .icon("dialog-warning")
21 /// .urgency(Urgency::Critical)
22 /// .show()?;
23 /// # Ok(())
24 /// # }
25 /// ```
26 ///
27 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
28 pub enum Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency# {
29 /// The behavior for `Low` urgency depends on the notification server.
30 Lowrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Low# = 0,
31 /// The behavior for `Normal` urgency depends on the notification server.
32 Normalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Normal# = 1,
33 /// A critical notification will not time out.
34 Criticalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Critical# = 2,
35 }
36
37 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&str> for Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency# {
38 type Errorrust-analyzer cargo notify-rust 4.18.0 urgency/impl#[Urgency][`TryFrom<&str>`]Error# = craterust-analyzer cargo notify-rust 4.18.0 crate/::errorrust-analyzer cargo notify-rust 4.18.0 error/::Errorrust-analyzer cargo notify-rust 4.18.0 error/Error#;
39
40 #[rustfmt::skip]
41 fn try_fromrust-analyzer cargo notify-rust 4.18.0 urgency/impl#[Urgency][`TryFrom<&str>`]try_from().(string: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#, Selfrust-analyzer cargo notify-rust 4.18.0 urgency/impl#[Urgency][`TryFrom<&str>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> {
42 match string.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().().as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().() {
43 "low" |
44 "lo" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Lowrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Low#),
45 "normal" |
46 "medium" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Normalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Normal#),
47 "critical" |
48 "high" |
49 "hi" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Criticalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Critical#),
50 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ErrorKindrust-analyzer cargo notify-rust 4.18.0 error/ErrorKind#::Conversionrust-analyzer cargo notify-rust 4.18.0 error/ErrorKind#Conversion#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid input {string:?}")).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
51 }
52 }
53 }
54
55 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>> for Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency# {
56 fn fromrust-analyzer cargo notify-rust 4.18.0 urgency/impl#[Urgency][`From<Option<u64>>`]from().(maybe_int: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>) -> Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency# {
57 match maybe_int {
58 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0) => Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Lowrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Low#,
59 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) if x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().2 => Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Criticalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Critical#,
60 _ => Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Normalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Normal#,
61 }
62 }
63 }
64
65 // TODO: remove this in v5.0
66 // #[cfg(not(feature = "server"))]
67 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<u64> for Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency# {
68 fn fromrust-analyzer cargo notify-rust 4.18.0 urgency/impl#[Urgency][`From<u64>`]from().(int: u64) -> Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency# {
69 match int {
70 0 => Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Lowrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Low#,
71 1 => Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Normalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Normal#,
72 2..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX. => Urgencyrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#::Criticalrust-analyzer cargo notify-rust 4.18.0 urgency/Urgency#Critical#,
73 }
74 }
75 }
76
77 // // TODO: make this the default in v5.0
78 // #[cfg(feature = "server")]
79 // impl From<u8> for Urgency {
80 // fn from(int: u8) -> Urgency {
81 // match int {
82 // 0 => Urgency::Low,
83 // 1 => Urgency::Normal,
84 // 2..=std::u8::MAX => Urgency::Critical,
85 // }
86 // }
87 // }