nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

close.rs (922B)


      1 //! Subscription close request parsing
      2 //!
      3 //! Representation and parsing of `CLOSE` messages sent from clients.
      4 use crate::error::{Error, Result};
      5 use serde::{Deserialize, Serialize};
      6 
      7 /// Close command in network format
      8 #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
      9 pub struct CloseCmd {
     10     /// Protocol command, expected to always be "CLOSE".
     11     cmd: String,
     12     /// The subscription identifier being closed.
     13     id: String,
     14 }
     15 
     16 /// Identifier of the subscription to be closed.
     17 #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
     18 pub struct Close {
     19     /// The subscription identifier being closed.
     20     pub id: String,
     21 }
     22 
     23 impl From<CloseCmd> for Result<Close> {
     24     fn from(cc: CloseCmd) -> Result<Close> {
     25         // ensure command is correct
     26         if cc.cmd == "CLOSE" {
     27             Ok(Close { id: cc.id })
     28         } else {
     29             Err(Error::CommandUnknownError)
     30         }
     31     }
     32 }