-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat!: support multiple arguments to the payload #384
Conversation
Added new payload variant to support multiple arguments. The old Payload::String is deprecated, and will be removed shortly. Also fixed running doc tests in the devcontainer
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #384 +/- ##
==========================================
+ Coverage 90.78% 91.39% +0.61%
==========================================
Files 37 37
Lines 4708 4837 +129
==========================================
+ Hits 4274 4421 +147
+ Misses 434 416 -18 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just nits! Thanks a lot Nathan :)
Do you think we still need the other PR? Probably we could just use this one, right?
socketio/examples/async.rs
Outdated
@@ -14,8 +14,11 @@ async fn main() { | |||
let callback = |payload: Payload, socket: Client| { | |||
async move { | |||
match payload { | |||
Payload::String(str) => println!("Received: {}", str), | |||
Payload::Text(values) => println!("Received: {:?}", values), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe switch formatting to {:#?}
to be consistent with how we format bytes in the next line?
socketio/examples/callback.rs
Outdated
@@ -11,8 +11,11 @@ fn main() { | |||
// socket to communicate with the server | |||
let handle_test = |payload: Payload, socket: RawClient| { | |||
match payload { | |||
Payload::String(str) => println!("Received string: {}", str), | |||
Payload::Text(text) => println!("Received json: {:?}", text), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe switch formatting to {:#?}
to be consistent with how we format bytes in the next line?
socketio/examples/readme.rs
Outdated
Payload::String(str) => println!("Received: {}", str), | ||
Payload::Text(text) => println!("Received json: {:?}", text), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Same as the others, maybe switch to {:#?}
?
@@ -48,8 +48,10 @@ impl ClientBuilder { | |||
/// let callback = |payload: Payload, socket: Client| { | |||
/// async move { | |||
/// match payload { | |||
/// Payload::String(str) => println!("Received: {}", str), | |||
/// Payload::Text(values) => println!("Received: {:?}", values), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same as the others
@@ -112,8 +114,10 @@ impl ClientBuilder { | |||
/// .on("test", |payload: Payload, _| { | |||
/// async move { | |||
/// match payload { | |||
/// Payload::String(str) => println!("Received: {}", str), | |||
/// Payload::Binary(bin_data) => println!("Received bytes: {:#?}", bin_data), | |||
/// Payload::Text(values) => println!("Received: {:?}", values), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same
@@ -456,6 +457,8 @@ mod test { | |||
.on("test", |msg, _| { | |||
async { | |||
match msg { | |||
Payload::Text(values) => println!("Received json: {:?}", values), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same. Note to myself: we really do format that a lot...
println!("Ack data: {}", str); | ||
if let Payload::Text(json) = message { | ||
println!("Received json Ack"); | ||
println!("Ack data: {:?}", json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same
if let Payload::String(str) = payload { | ||
println!("{event}: {str}"); | ||
if let Payload::Text(values) = payload { | ||
println!("{event}: {values:?}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same
/// Returns a packet for a payload, could be used for both binary and non binary | ||
/// events and acks. Convenience method. | ||
#[inline] | ||
pub(crate) fn new_from_payload<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just name it new
?
We take way more than just the payload to create it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a different new
with args down here:
rust-socketio/socketio/src/packet.rs
Line 70 in 38f20fc
pub const fn new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks :)
Added new payload variant called
Text
to support multiple arguments encoded in JSON. The old Payload::String is deprecated, and will be removed shortly. UsePayload::from(String)
to mimic old behaviorBuilt on top of @SalahaldinBilal 's work #379
Also fixed running doc tests in the devcontainer