use std::borrow::Cow;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CloseFrame<'a> {
pub code: u16,
pub reason: Cow<'a, str>,
}
impl<'a> CloseFrame<'a> {
pub const NORMAL: Self = Self::new(1000, "closing connection");
pub const RESUME: Self = Self::new(4000, "resuming connection");
pub const fn new(code: u16, reason: &'a str) -> Self {
Self {
code,
reason: Cow::Borrowed(reason),
}
}
}
#[cfg(test)]
mod tests {
use super::CloseFrame;
use static_assertions::assert_impl_all;
use std::fmt::Debug;
assert_impl_all!(
CloseFrame<'_>:
Clone,
Debug,
Eq,
PartialEq,
);
}