Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes derive_more #48

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ tokio-util = "0.7.4"
tokio-stream = "0.1.11"
futures = "0.3.4"
futures-util = "0.3.4"
derive_more = "0.99.14"
thiserror = "1.0"
bytes = "1.0"
rand = "0.8"
Expand Down
1 change: 0 additions & 1 deletion ratchet_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ tokio = { workspace = true, features = ["rt", "net", "io-util"] }
tokio-util = { workspace = true, features = ["codec", "compat"] }
futures = { workspace = true, optional = true }
futures-util = { workspace = true }
derive_more = { workspace = true }
thiserror = { workspace = true }
bytes = { workspace = true }
rand = { workspace = true, features = ["std", "small_rng", "getrandom"] }
Expand Down
28 changes: 22 additions & 6 deletions ratchet_core/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub use frame::*;
pub use mask::apply_mask;

use bytes::Bytes;
use derive_more::Display;
use std::convert::TryFrom;
use std::fmt::{Display, Formatter};
use thiserror::Error;

bitflags::bitflags! {
Expand Down Expand Up @@ -166,14 +166,18 @@ impl Role {
}
}

#[derive(Debug, Copy, Clone, Display, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum OpCode {
#[display(fmt = "{}", _0)]
DataCode(DataCode),
#[display(fmt = "{}", _0)]
ControlCode(ControlCode),
}

impl Display for OpCode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

impl OpCode {
pub fn is_data(&self) -> bool {
matches!(self, OpCode::DataCode(_))
Expand All @@ -193,13 +197,19 @@ impl From<OpCode> for u8 {
}
}

#[derive(Debug, Copy, Clone, Display, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DataCode {
Continuation = 0,
Text = 1,
Binary = 2,
}

impl Display for DataCode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

impl From<DataCode> for ratchet_ext::OpCode {
fn from(e: DataCode) -> Self {
match e {
Expand All @@ -210,13 +220,19 @@ impl From<DataCode> for ratchet_ext::OpCode {
}
}

#[derive(Debug, Copy, Clone, Display, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ControlCode {
Close = 8,
Ping = 9,
Pong = 10,
}

impl Display for ControlCode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

#[derive(Copy, Clone, Debug, Error, PartialEq, Eq)]
pub enum OpCodeParseErr {
#[error("Reserved OpCode: `{0}`")]
Expand Down
Loading