We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e1821db commit e3e6f7fCopy full SHA for e3e6f7f
crates/json-rpc/src/packet.rs
@@ -47,6 +47,22 @@ impl RequestPacket {
47
Self::Batch(Vec::with_capacity(capacity))
48
}
49
50
+ /// Returns the [`SerializedRequest`] if this packet is [`ResponsePacket::Single`]
51
+ pub const fn as_single(&self) -> Option<&SerializedRequest> {
52
+ match self {
53
+ Self::Single(req) => Some(req),
54
+ Self::Batch(_) => None,
55
+ }
56
57
+
58
+ /// Returns the batch of [`SerializedRequest`] if this packet is [`ResponsePacket::Batch`]
59
+ pub fn as_batch(&self) -> Option<&[SerializedRequest]> {
60
61
+ Self::Batch(req) => Some(req.as_slice()),
62
+ Self::Single(_) => None,
63
64
65
66
/// Serialize the packet as a boxed [`RawValue`].
67
pub fn serialize(self) -> serde_json::Result<Box<RawValue>> {
68
match self {
0 commit comments