Debian Codegraph @

src/timeout.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#, strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#, timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#};
2
3 /// Describes the timeout of a notification
4 ///
5 /// # `FromStr`
6 /// You can also parse a `Timeout` from a `&str`.
7 /// ```
8 /// # use notify_rust::Timeout;
9 /// assert_eq!("default".parse(), Ok(Timeout::Default));
10 /// assert_eq!("never".parse(), Ok(Timeout::Never));
11 /// assert_eq!("42".parse(), Ok(Timeout::Milliseconds(42)));
12 /// ```
13 #[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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, 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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
14 pub enum Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout# {
15 /// Expires according to server default.
16 ///
17 /// Whatever that might be...
18 #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:]
19 Defaultrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Default#,
20
21 /// Do not expire, user will have to close this manually.
22 Neverrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Never#,
23
24 /// Expire after n milliseconds.
25 Millisecondsrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Milliseconds#(u32),
26 }
27
28 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
29 fn timeout_from_i32rust-analyzer cargo notify-rust 4.18.0 timeout/timeout_from_i32().() {
30 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][`From<i32>`]from().(234), Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Millisecondsrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Milliseconds#(234));
31 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][`From<i32>`]from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().234), Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Defaultrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Default#);
32 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][`From<i32>`]from().(0), Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Neverrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Never#);
33 }
34
35 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<i32> for Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout# {
36 fn fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][`From<i32>`]from().(int: i32) -> Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout# {
37 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::*;
38 match int.cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][Ord]cmp().(&0) {
39 Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Millisecondsrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Milliseconds#(int as u32),
40 Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Defaultrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Default#,
41 Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Neverrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Never#,
42 }
43 }
44 }
45
46 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#> for Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout# {
47 fn fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][`From<Duration>`]from().(duration: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) -> Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout# {
48 if duration.is_zerorust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]is_zero().() {
49 Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Neverrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Never#
50 } else if duration.as_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_millis().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]gt().u32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]MAX. as u128 {
51 Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Defaultrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Default#
52 } else {
53 Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Millisecondsrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Milliseconds#(duration.as_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_millis().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(u32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]MAX.))
54 }
55 }
56 }
57
58 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#> for i32 {
59 fn fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[i32][`From<Timeout>`]from().(timeout: Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#) -> Selfrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[i32][`From<Timeout>`] {
60 match timeout {
61 Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Defaultrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Default# => -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1,
62 Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Neverrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Never# => 0,
63 Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Millisecondsrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Milliseconds#(ms) => ms as i32,
64 }
65 }
66 }
67
68 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout# {
69 type Errrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][FromStr]Err# = ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#;
70
71 fn from_strrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][FromStr], Selfrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[Timeout][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
72 match s {
73 "default" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Defaultrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Default#),
74 "never" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Neverrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Never#),
75 milliseconds => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#::Millisecondsrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#Milliseconds#(u32::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32][FromStr]from_str().(milliseconds)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)),
76 }
77 }
78 }
79
80 #[cfg(all(feature = "dbus", unix, not(target_os = "macos")))]
81 pub struct TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage#(Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#);
82
83 #[cfg(all(feature = "dbus", unix, not(target_os = "macos")))]
84 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#> for TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage# {
85 fn fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][`From<Timeout>`]from().(hint: Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#) -> Selfrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][`From<Timeout>`] {
86 TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage#(hint)
87 }
88 }
89
90 #[cfg(all(feature = "dbus", unix, not(target_os = "macos")))]
91 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage# {
92 type Targetrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][Deref]Target# = Timeoutrust-analyzer cargo notify-rust 4.18.0 timeout/Timeout#;
93
94 fn derefrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][Deref]deref().(&self) -> &Selfrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
95 &self.0rust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage#0.
96 }
97 }
98
99 #[cfg(all(feature = "dbus", unix, not(target_os = "macos")))]
100 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&dbusrust-analyzer cargo dbus 0.9.12 crate/::argrust-analyzer cargo dbus 0.9.12 arg/::messageitemrust-analyzer cargo dbus 0.9.12 arg/messageitem/::MessageItemrust-analyzer cargo dbus 0.9.12 arg/messageitem/MessageItem#> for TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage# {
101 type Errorrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][`TryFrom<&dbus::arg::messageitem::MessageItem>`]Error# = ();
102
103 fn try_fromrust-analyzer cargo notify-rust 4.18.0 timeout/impl#[TimeoutMessage][`TryFrom<&dbus::arg::messageitem::MessageItem>`]try_from().(mi: &dbusrust-analyzer cargo dbus 0.9.12 crate/::argrust-analyzer cargo dbus 0.9.12 arg/::messageitemrust-analyzer cargo dbus 0.9.12 arg/messageitem/::MessageItemrust-analyzer cargo dbus 0.9.12 arg/messageitem/MessageItem#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage#, ()> {
104 mi.innerrust-analyzer cargo dbus 0.9.12 arg/messageitem/impl#[MessageItem]inner().::<i32>().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|i| TimeoutMessagerust-analyzer cargo notify-rust 4.18.0 timeout/TimeoutMessage#(i.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
105 }
106 }