diff --git a/core/Cargo.toml b/core/Cargo.toml index a890298d17..fb7b0475c3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,7 +16,6 @@ publish = true [dependencies] anyhow = "1" async-trait = "0.1" -beef = { version = "0.5.1", features = ["impl_serde"] } jsonrpsee-types = { workspace = true } thiserror = "1" serde = { version = "1.0", default-features = false, features = ["derive"] } diff --git a/core/src/lib.rs b/core/src/lib.rs index 31f6dacc80..075ddd5cde 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -81,12 +81,12 @@ pub mod __reexports { } } -pub use beef::Cow; pub use serde::{de::DeserializeOwned, Serialize}; pub use serde_json::{ to_value as to_json_value, value::to_raw_value as to_json_raw_value, value::RawValue as JsonRawValue, Value as JsonValue, }; +pub use std::borrow::Cow; /// Ten megabytes. pub const TEN_MB_SIZE_BYTES: u32 = 10 * 1024 * 1024; diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 49bf5d3665..75be704047 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -9,7 +9,6 @@ publish = false [dev-dependencies] anyhow = "1" -beef = { version = "0.5.1", features = ["impl_serde"] } fast-socks5 = { version = "0.9.1" } futures = { version = "0.3.14", default-features = false, features = ["std"] } futures-util = { version = "0.3.14", default-features = false, features = ["alloc"]} diff --git a/tests/tests/proc_macros.rs b/tests/tests/proc_macros.rs index 182481d01e..baf5f676b5 100644 --- a/tests/tests/proc_macros.rs +++ b/tests/tests/proc_macros.rs @@ -107,18 +107,14 @@ mod rpc_impl { a: &str, b: &'_ str, c: std::borrow::Cow<'_, str>, - d: Option>, + d: Option>, ) -> Result { Ok(format!("Called with: {}, {}, {}, {:?}", a, b, c, d)) } #[method(name = "zero_copy_cow")] - fn zero_copy_cow( - &self, - a: std::borrow::Cow<'_, str>, - b: beef::Cow<'_, str>, - ) -> Result { - Ok(format!("Zero copy params: {}, {}", matches!(a, std::borrow::Cow::Borrowed(_)), b.is_borrowed())) + fn zero_copy_cow(&self, a: std::borrow::Cow<'_, str>) -> Result { + Ok(format!("Zero copy params: {}", matches!(a, std::borrow::Cow::Borrowed(_)))) } #[method(name = "blocking_call", blocking)] @@ -285,19 +281,19 @@ async fn macro_zero_copy_cow() { let module = RpcServerImpl.into_rpc(); let (resp, _) = module - .raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["foo", "bar"],"id":0}"#, 1) + .raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["foo"],"id":0}"#, 1) .await .unwrap(); // std::borrow::Cow always deserialized to owned variant here - assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false, true","id":0}"#); + assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false","id":0}"#); // serde_json will have to allocate a new string to replace `\t` with byte 0x09 (tab) let (resp, _) = module - .raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["\tfoo", "\tbar"],"id":0}"#, 1) + .raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["\tfoo"],"id":0}"#, 1) .await .unwrap(); - assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false, false","id":0}"#); + assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false","id":0}"#); } // Disabled on MacOS as GH CI timings on Mac vary wildly (~100ms) making this test fail. diff --git a/types/Cargo.toml b/types/Cargo.toml index 9558061bc0..62039633b2 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -14,7 +14,6 @@ readme.workspace = true publish = true [dependencies] -beef = { version = "0.5.1", features = ["impl_serde"] } serde = { version = "1", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, features = ["alloc", "raw_value", "std"] } thiserror = "1.0" diff --git a/types/src/params.rs b/types/src/params.rs index c86379b556..db97147808 100644 --- a/types/src/params.rs +++ b/types/src/params.rs @@ -27,9 +27,9 @@ //! Types to handle JSON-RPC request parameters according to the [spec](https://www.jsonrpc.org/specification#parameter_structures). //! Some types come with a "*Ser" variant that implements [`serde::Serialize`]; these are used in the client. +use std::borrow::Cow; use std::fmt; -use beef::Cow; use serde::de::{self, Deserializer, Unexpected, Visitor}; use serde::ser::Serializer; use serde::{Deserialize, Serialize}; @@ -139,7 +139,7 @@ impl<'a> Params<'a> { /// /// This will cause an allocation if the params internally are using a borrowed JSON slice. pub fn into_owned(self) -> Params<'static> { - Params(self.0.map(|s| Cow::owned(s.into_owned()))) + Params(self.0.map(|s| Cow::Owned(s.into_owned()))) } /// Return the length of underlying JSON string in number of bytes. @@ -315,7 +315,7 @@ impl<'a> SubscriptionId<'a> { pub fn into_owned(self) -> SubscriptionId<'static> { match self { SubscriptionId::Num(num) => SubscriptionId::Num(num), - SubscriptionId::Str(s) => SubscriptionId::Str(Cow::owned(s.into_owned())), + SubscriptionId::Str(s) => SubscriptionId::Str(Cow::Owned(s.into_owned())), } } } @@ -382,7 +382,7 @@ impl<'a> Id<'a> { match self { Id::Null => Id::Null, Id::Number(num) => Id::Number(num), - Id::Str(s) => Id::Str(Cow::owned(s.into_owned())), + Id::Str(s) => Id::Str(Cow::Owned(s.into_owned())), } } @@ -421,7 +421,7 @@ mod test { let deserialized: Id = serde_json::from_str(s).unwrap(); match deserialized { Id::Str(ref cow) => { - assert!(cow.is_borrowed()); + assert!(matches!(cow, Cow::Borrowed(_))); assert_eq!(cow, "2"); } _ => panic!("Expected Id::Str"), @@ -433,7 +433,7 @@ mod test { let s = r#""2x""#; let deserialized: Id = serde_json::from_str(s).unwrap(); - assert_eq!(deserialized, Id::Str(Cow::const_str("2x"))); + assert_eq!(deserialized, Id::Str(Cow::Borrowed("2x"))); let s = r#"[1337]"#; assert!(serde_json::from_str::(s).is_err()); diff --git a/types/src/request.rs b/types/src/request.rs index 6cfd8dacc8..28026a0392 100644 --- a/types/src/request.rs +++ b/types/src/request.rs @@ -27,13 +27,12 @@ //! Types to handle JSON-RPC requests according to the [spec](https://www.jsonrpc.org/specification#request-object). //! Some types come with a "*Ser" variant that implements [`serde::Serialize`]; these are used in the client. -use std::borrow::Cow as StdCow; +use std::borrow::Cow; use crate::{ params::{Id, TwoPointZero}, Params, }; -use beef::Cow; use http::Extensions; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue; @@ -51,7 +50,7 @@ pub struct Request<'a> { pub method: Cow<'a, str>, /// Parameter values of the request. #[serde(borrow)] - pub params: Option>, + pub params: Option>, /// The request's extensions. #[serde(skip)] pub extensions: Extensions, @@ -60,7 +59,7 @@ pub struct Request<'a> { impl<'a> Request<'a> { /// Create a new [`Request`]. pub fn new(method: Cow<'a, str>, params: Option<&'a RawValue>, id: Id<'a>) -> Self { - Self { jsonrpc: TwoPointZero, id, method, params: params.map(StdCow::Borrowed), extensions: Extensions::new() } + Self { jsonrpc: TwoPointZero, id, method, params: params.map(Cow::Borrowed), extensions: Extensions::new() } } /// Get the ID of the request. @@ -129,7 +128,7 @@ pub struct RequestSer<'a> { pub method: Cow<'a, str>, /// Parameter values of the request. #[serde(skip_serializing_if = "Option::is_none")] - pub params: Option>, + pub params: Option>, } impl<'a> RequestSer<'a> { @@ -139,13 +138,13 @@ impl<'a> RequestSer<'a> { jsonrpc: TwoPointZero, id: id.clone(), method: method.as_ref().into(), - params: params.map(StdCow::Borrowed), + params: params.map(Cow::Borrowed), } } /// Create a owned serializable JSON-RPC method call. pub fn owned(id: Id<'a>, method: impl Into, params: Option>) -> Self { - Self { jsonrpc: TwoPointZero, id, method: method.into().into(), params: params.map(StdCow::Owned) } + Self { jsonrpc: TwoPointZero, id, method: method.into().into(), params: params.map(Cow::Owned) } } } @@ -159,24 +158,24 @@ pub struct NotificationSer<'a> { pub method: Cow<'a, str>, /// Parameter values of the request. #[serde(skip_serializing_if = "Option::is_none")] - pub params: Option>, + pub params: Option>, } impl<'a> NotificationSer<'a> { /// Create a borrowed serializable JSON-RPC notification. pub fn borrowed(method: &'a impl AsRef, params: Option<&'a RawValue>) -> Self { - Self { jsonrpc: TwoPointZero, method: method.as_ref().into(), params: params.map(StdCow::Borrowed) } + Self { jsonrpc: TwoPointZero, method: method.as_ref().into(), params: params.map(Cow::Borrowed) } } /// Create an owned serializable JSON-RPC notification. pub fn owned(method: impl Into, params: Option>) -> Self { - Self { jsonrpc: TwoPointZero, method: method.into().into(), params: params.map(StdCow::Owned) } + Self { jsonrpc: TwoPointZero, method: method.into().into(), params: params.map(Cow::Owned) } } } #[cfg(test)] mod test { - use super::{Id, InvalidRequest, Notification, NotificationSer, Request, RequestSer, StdCow, TwoPointZero}; + use super::{Cow, Id, InvalidRequest, Notification, NotificationSer, Request, RequestSer, TwoPointZero}; use serde_json::value::RawValue; fn assert_request<'a>(request: Request<'a>, id: Id<'a>, method: &str, params: Option<&str>) { @@ -278,7 +277,7 @@ mod test { jsonrpc: TwoPointZero, method: method.into(), id: id.unwrap_or(Id::Null), - params: params.map(StdCow::Owned), + params: params.map(Cow::Owned), }) .unwrap();