Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unsafe conversions
  • Loading branch information
benashford committed Jan 2, 2021
commit 53a4af2535afaaa9cc88a557ca8511a17a53116d
2 changes: 1 addition & 1 deletion examples/realistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn do_main() {
let connection_inner = connection.clone();
let incr_f = connection.send(resp_array!["INCR", "realistic_test_ctr"]);
async move {
let ctr: String = incr_f.await.expect("Cannot increment");
let ctr: i64 = incr_f.await.expect("Cannot increment");

let key = format!("rt_{}", ctr);
let d_val = data.0.to_string();
Expand Down
1 change: 1 addition & 0 deletions examples/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async fn do_main() {
let topic = env::args()
.nth(1)
.unwrap_or_else(|| "test-topic".to_string());

let addr = env::args()
.nth(2)
.unwrap_or_else(|| "127.0.0.1:6379".to_string());
Expand Down
22 changes: 19 additions & 3 deletions src/protocol/resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,28 @@ macro_rules! integer_into_resp {
};
}

impl ToRespInteger for usize {
impl ToRespInteger for i64 {
fn to_resp_integer(self) -> RespValue {
RespValue::Integer(self as i64)
RespValue::Integer(self)
}
}
integer_into_resp!(usize);
integer_into_resp!(i64);

macro_rules! impl_toresp_integers {
($($int_ty:ident),* $(,)*) => {
$(
impl ToRespInteger for $int_ty {
fn to_resp_integer(self) -> RespValue {
let new_self = self as i64;
new_self.to_resp_integer()
}
}
integer_into_resp!($int_ty);
)*
};
}

impl_toresp_integers!(isize, i32, u32);

#[cfg(test)]
mod tests {
Expand Down