nostr-rs-relay/src/close.rs

33 lines
922 B
Rust
Raw Permalink Normal View History

2021-12-11 22:43:41 -05:00
//! Subscription close request parsing
2022-02-12 10:29:35 -05:00
//!
//! Representation and parsing of `CLOSE` messages sent from clients.
use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
2021-12-11 22:43:41 -05:00
/// Close command in network format
2022-09-24 09:30:22 -04:00
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct CloseCmd {
2021-12-11 22:43:41 -05:00
/// Protocol command, expected to always be "CLOSE".
cmd: String,
2021-12-11 22:43:41 -05:00
/// The subscription identifier being closed.
id: String,
}
2022-02-12 10:29:35 -05:00
/// Identifier of the subscription to be closed.
2022-09-24 09:30:22 -04:00
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct Close {
2021-12-11 22:43:41 -05:00
/// The subscription identifier being closed.
pub id: String,
}
impl From<CloseCmd> for Result<Close> {
fn from(cc: CloseCmd) -> Result<Close> {
// ensure command is correct
2022-09-24 10:01:09 -04:00
if cc.cmd == "CLOSE" {
2021-12-11 22:56:52 -05:00
Ok(Close { id: cc.id })
2022-09-24 10:01:09 -04:00
} else {
Err(Error::CommandUnknownError)
}
}
}