toad_msg/msg/opt/known/
observe.rs

1/// When included in a GET request, the Observe Option extends the GET
2/// method so it does not only retrieve a current representation of the
3/// target resource, but also requests the server to add or remove an
4/// entry in the list of observers of the resource depending on the
5/// option value.  The list entry consists of the client endpoint and the
6/// token specified by the client in the request.  Possible values are:
7///
8///    `0` (register) adds the entry to the list, if not present;
9///
10///    `1` (deregister) removes the entry from the list, if present
11#[derive(Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
12pub enum Action {
13  /// Tells the resource owner we would like to observe updates to
14  /// the resource we've issued a GET request for.
15  Register,
16  /// Tells the resource owner we would no longer like to observe updates to
17  /// the resource we've issued a GET request for.
18  Deregister,
19}
20
21impl Action {
22  /// Try to parse from a single byte
23  pub fn from_byte(n: u8) -> Option<Self> {
24    match n {
25      | 0 => Some(Action::Register),
26      | 1 => Some(Action::Deregister),
27      | _ => None,
28    }
29  }
30}
31
32impl From<Action> for u8 {
33  fn from(a: Action) -> Self {
34    match a {
35      | Action::Register => 0,
36      | Action::Deregister => 1,
37    }
38  }
39}