Skip to content

Commit b9ef76e

Browse files
committed
deps: remove beef
1 parent 717e9fe commit b9ef76e

File tree

7 files changed

+25
-33
lines changed

7 files changed

+25
-33
lines changed

core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ publish = true
1616
[dependencies]
1717
anyhow = "1"
1818
async-trait = "0.1"
19-
beef = { version = "0.5.1", features = ["impl_serde"] }
2019
jsonrpsee-types = { workspace = true }
2120
thiserror = "1"
2221
serde = { version = "1.0", default-features = false, features = ["derive"] }

core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ pub mod __reexports {
8181
}
8282
}
8383

84-
pub use beef::Cow;
8584
pub use serde::{de::DeserializeOwned, Serialize};
8685
pub use serde_json::{
8786
to_value as to_json_value, value::to_raw_value as to_json_raw_value, value::RawValue as JsonRawValue,
8887
Value as JsonValue,
8988
};
89+
pub use std::borrow::Cow;
9090

9191
/// Ten megabytes.
9292
pub const TEN_MB_SIZE_BYTES: u32 = 10 * 1024 * 1024;

tests/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ publish = false
99

1010
[dev-dependencies]
1111
anyhow = "1"
12-
beef = { version = "0.5.1", features = ["impl_serde"] }
1312
fast-socks5 = { version = "0.9.1" }
1413
futures = { version = "0.3.14", default-features = false, features = ["std"] }
1514
futures-util = { version = "0.3.14", default-features = false, features = ["alloc"]}

tests/tests/proc_macros.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,14 @@ mod rpc_impl {
107107
a: &str,
108108
b: &'_ str,
109109
c: std::borrow::Cow<'_, str>,
110-
d: Option<beef::Cow<'_, str>>,
110+
d: Option<std::borrow::Cow<'_, str>>,
111111
) -> Result<String, ErrorObjectOwned> {
112112
Ok(format!("Called with: {}, {}, {}, {:?}", a, b, c, d))
113113
}
114114

115115
#[method(name = "zero_copy_cow")]
116-
fn zero_copy_cow(
117-
&self,
118-
a: std::borrow::Cow<'_, str>,
119-
b: beef::Cow<'_, str>,
120-
) -> Result<String, ErrorObjectOwned> {
121-
Ok(format!("Zero copy params: {}, {}", matches!(a, std::borrow::Cow::Borrowed(_)), b.is_borrowed()))
116+
fn zero_copy_cow(&self, a: std::borrow::Cow<'_, str>) -> Result<String, ErrorObjectOwned> {
117+
Ok(format!("Zero copy params: {}", matches!(a, std::borrow::Cow::Borrowed(_))))
122118
}
123119

124120
#[method(name = "blocking_call", blocking)]
@@ -285,19 +281,19 @@ async fn macro_zero_copy_cow() {
285281
let module = RpcServerImpl.into_rpc();
286282

287283
let (resp, _) = module
288-
.raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["foo", "bar"],"id":0}"#, 1)
284+
.raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["foo"],"id":0}"#, 1)
289285
.await
290286
.unwrap();
291287

292288
// std::borrow::Cow<str> always deserialized to owned variant here
293-
assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false, true","id":0}"#);
289+
assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false","id":0}"#);
294290

295291
// serde_json will have to allocate a new string to replace `\t` with byte 0x09 (tab)
296292
let (resp, _) = module
297-
.raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["\tfoo", "\tbar"],"id":0}"#, 1)
293+
.raw_json_request(r#"{"jsonrpc":"2.0","method":"foo_zero_copy_cow","params":["\tfoo"],"id":0}"#, 1)
298294
.await
299295
.unwrap();
300-
assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false, false","id":0}"#);
296+
assert_eq!(resp, r#"{"jsonrpc":"2.0","result":"Zero copy params: false","id":0}"#);
301297
}
302298

303299
// Disabled on MacOS as GH CI timings on Mac vary wildly (~100ms) making this test fail.

types/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ readme.workspace = true
1414
publish = true
1515

1616
[dependencies]
17-
beef = { version = "0.5.1", features = ["impl_serde"] }
1817
serde = { version = "1", default-features = false, features = ["derive"] }
1918
serde_json = { version = "1", default-features = false, features = ["alloc", "raw_value", "std"] }
2019
thiserror = "1.0"

types/src/params.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
//! Types to handle JSON-RPC request parameters according to the [spec](https://www.jsonrpc.org/specification#parameter_structures).
2828
//! Some types come with a "*Ser" variant that implements [`serde::Serialize`]; these are used in the client.
2929
30+
use std::borrow::Cow;
3031
use std::fmt;
3132

32-
use beef::Cow;
3333
use serde::de::{self, Deserializer, Unexpected, Visitor};
3434
use serde::ser::Serializer;
3535
use serde::{Deserialize, Serialize};
@@ -139,7 +139,7 @@ impl<'a> Params<'a> {
139139
///
140140
/// This will cause an allocation if the params internally are using a borrowed JSON slice.
141141
pub fn into_owned(self) -> Params<'static> {
142-
Params(self.0.map(|s| Cow::owned(s.into_owned())))
142+
Params(self.0.map(|s| Cow::Owned(s.into_owned())))
143143
}
144144

145145
/// Return the length of underlying JSON string in number of bytes.
@@ -315,7 +315,7 @@ impl<'a> SubscriptionId<'a> {
315315
pub fn into_owned(self) -> SubscriptionId<'static> {
316316
match self {
317317
SubscriptionId::Num(num) => SubscriptionId::Num(num),
318-
SubscriptionId::Str(s) => SubscriptionId::Str(Cow::owned(s.into_owned())),
318+
SubscriptionId::Str(s) => SubscriptionId::Str(Cow::Owned(s.into_owned())),
319319
}
320320
}
321321
}
@@ -382,7 +382,7 @@ impl<'a> Id<'a> {
382382
match self {
383383
Id::Null => Id::Null,
384384
Id::Number(num) => Id::Number(num),
385-
Id::Str(s) => Id::Str(Cow::owned(s.into_owned())),
385+
Id::Str(s) => Id::Str(Cow::Owned(s.into_owned())),
386386
}
387387
}
388388

@@ -421,7 +421,7 @@ mod test {
421421
let deserialized: Id = serde_json::from_str(s).unwrap();
422422
match deserialized {
423423
Id::Str(ref cow) => {
424-
assert!(cow.is_borrowed());
424+
assert!(matches!(cow, Cow::Borrowed(_)));
425425
assert_eq!(cow, "2");
426426
}
427427
_ => panic!("Expected Id::Str"),
@@ -433,7 +433,7 @@ mod test {
433433

434434
let s = r#""2x""#;
435435
let deserialized: Id = serde_json::from_str(s).unwrap();
436-
assert_eq!(deserialized, Id::Str(Cow::const_str("2x")));
436+
assert_eq!(deserialized, Id::Str(Cow::Borrowed("2x")));
437437

438438
let s = r#"[1337]"#;
439439
assert!(serde_json::from_str::<Id>(s).is_err());

types/src/request.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
//! Types to handle JSON-RPC requests according to the [spec](https://www.jsonrpc.org/specification#request-object).
2828
//! Some types come with a "*Ser" variant that implements [`serde::Serialize`]; these are used in the client.
2929
30-
use std::borrow::Cow as StdCow;
30+
use std::borrow::Cow;
3131

3232
use crate::{
3333
params::{Id, TwoPointZero},
3434
Params,
3535
};
36-
use beef::Cow;
3736
use http::Extensions;
3837
use serde::{Deserialize, Serialize};
3938
use serde_json::value::RawValue;
@@ -51,7 +50,7 @@ pub struct Request<'a> {
5150
pub method: Cow<'a, str>,
5251
/// Parameter values of the request.
5352
#[serde(borrow)]
54-
pub params: Option<StdCow<'a, RawValue>>,
53+
pub params: Option<Cow<'a, RawValue>>,
5554
/// The request's extensions.
5655
#[serde(skip)]
5756
pub extensions: Extensions,
@@ -60,7 +59,7 @@ pub struct Request<'a> {
6059
impl<'a> Request<'a> {
6160
/// Create a new [`Request`].
6261
pub fn new(method: Cow<'a, str>, params: Option<&'a RawValue>, id: Id<'a>) -> Self {
63-
Self { jsonrpc: TwoPointZero, id, method, params: params.map(StdCow::Borrowed), extensions: Extensions::new() }
62+
Self { jsonrpc: TwoPointZero, id, method, params: params.map(Cow::Borrowed), extensions: Extensions::new() }
6463
}
6564

6665
/// Get the ID of the request.
@@ -129,7 +128,7 @@ pub struct RequestSer<'a> {
129128
pub method: Cow<'a, str>,
130129
/// Parameter values of the request.
131130
#[serde(skip_serializing_if = "Option::is_none")]
132-
pub params: Option<StdCow<'a, RawValue>>,
131+
pub params: Option<Cow<'a, RawValue>>,
133132
}
134133

135134
impl<'a> RequestSer<'a> {
@@ -139,13 +138,13 @@ impl<'a> RequestSer<'a> {
139138
jsonrpc: TwoPointZero,
140139
id: id.clone(),
141140
method: method.as_ref().into(),
142-
params: params.map(StdCow::Borrowed),
141+
params: params.map(Cow::Borrowed),
143142
}
144143
}
145144

146145
/// Create a owned serializable JSON-RPC method call.
147146
pub fn owned(id: Id<'a>, method: impl Into<String>, params: Option<Box<RawValue>>) -> Self {
148-
Self { jsonrpc: TwoPointZero, id, method: method.into().into(), params: params.map(StdCow::Owned) }
147+
Self { jsonrpc: TwoPointZero, id, method: method.into().into(), params: params.map(Cow::Owned) }
149148
}
150149
}
151150

@@ -159,24 +158,24 @@ pub struct NotificationSer<'a> {
159158
pub method: Cow<'a, str>,
160159
/// Parameter values of the request.
161160
#[serde(skip_serializing_if = "Option::is_none")]
162-
pub params: Option<StdCow<'a, RawValue>>,
161+
pub params: Option<Cow<'a, RawValue>>,
163162
}
164163

165164
impl<'a> NotificationSer<'a> {
166165
/// Create a borrowed serializable JSON-RPC notification.
167166
pub fn borrowed(method: &'a impl AsRef<str>, params: Option<&'a RawValue>) -> Self {
168-
Self { jsonrpc: TwoPointZero, method: method.as_ref().into(), params: params.map(StdCow::Borrowed) }
167+
Self { jsonrpc: TwoPointZero, method: method.as_ref().into(), params: params.map(Cow::Borrowed) }
169168
}
170169

171170
/// Create an owned serializable JSON-RPC notification.
172171
pub fn owned(method: impl Into<String>, params: Option<Box<RawValue>>) -> Self {
173-
Self { jsonrpc: TwoPointZero, method: method.into().into(), params: params.map(StdCow::Owned) }
172+
Self { jsonrpc: TwoPointZero, method: method.into().into(), params: params.map(Cow::Owned) }
174173
}
175174
}
176175

177176
#[cfg(test)]
178177
mod test {
179-
use super::{Id, InvalidRequest, Notification, NotificationSer, Request, RequestSer, StdCow, TwoPointZero};
178+
use super::{Cow, Id, InvalidRequest, Notification, NotificationSer, Request, RequestSer, TwoPointZero};
180179
use serde_json::value::RawValue;
181180

182181
fn assert_request<'a>(request: Request<'a>, id: Id<'a>, method: &str, params: Option<&str>) {
@@ -278,7 +277,7 @@ mod test {
278277
jsonrpc: TwoPointZero,
279278
method: method.into(),
280279
id: id.unwrap_or(Id::Null),
281-
params: params.map(StdCow::Owned),
280+
params: params.map(Cow::Owned),
282281
})
283282
.unwrap();
284283

0 commit comments

Comments
 (0)