nostr-rs-relay/src/close.rs

31 lines
816 B
Rust
Raw Permalink Normal View History

2021-12-11 22:43:41 -05:00
//! Subscription close request parsing
use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
2021-12-11 22:43:41 -05:00
/// Close command in network format
#[derive(Serialize, Deserialize, PartialEq, 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,
}
2021-12-11 22:43:41 -05:00
/// Close command parsed
#[derive(Serialize, Deserialize, PartialEq, 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
if cc.cmd != "CLOSE" {
2021-12-11 22:56:52 -05:00
Err(Error::CommandUnknownError)
} else {
2021-12-11 22:56:52 -05:00
Ok(Close { id: cc.id })
}
}
}