Skip to content

Commit

Permalink
Fix several dozen issues to work on latest Rust again
Browse files Browse the repository at this point in the history
Remove old syntax (suffixes, ranges),
replace `as_slice()` calls where necessary
  • Loading branch information
badboy committed Mar 31, 2015
1 parent 8f63866 commit 88bc1fd
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn fetch_an_integer() -> redis::RedisResult<int> {
let client = try!(redis::Client::open("redis://127.0.0.1/"));
let con = try!(client.get_connection());
// throw away the result, just make sure it does not fail
let _ : () = try!(con.set("my_key", 42i));
let _ : () = try!(con.set("my_key", 42));
// read back the key and return it. Because the return value
// from the function is a result for integer this will automatically
// convert into one.
Expand Down
4 changes: 1 addition & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(core)]

extern crate redis;
use std::error::Error;
use redis::{Commands, PipelineCommands, transaction};
Expand Down Expand Up @@ -40,7 +38,7 @@ fn do_show_scanning(con: &redis::Connection) -> redis::RedisResult<()> {
// modified in place we can just ignore the return value upon the end
// of each iteration.
let mut pipe = redis::pipe();
for num in range(0, 1000) {
for num in 0..1000 {
pipe.cmd("SADD").arg("my_set").arg(num).ignore();
}

Expand Down
33 changes: 17 additions & 16 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ fn encode_pipeline(cmds: &[Cmd], atomic: bool) -> Vec<u8> {
/// Basic example:
///
/// ```rust
/// redis::Cmd::new().arg("SET").arg("my_key").arg(42i);
/// redis::Cmd::new().arg("SET").arg("my_key").arg(42);
/// ```
///
/// There is also a helper function called `cmd` which makes it a
/// tiny bit shorter:
///
/// ```rust
/// redis::cmd("SET").arg("my_key").arg(42i);
/// redis::cmd("SET").arg("my_key").arg(42);
/// ```
///
/// Because currently rust's currently does not have an ideal system
Expand Down Expand Up @@ -143,8 +143,8 @@ impl Cmd {
/// ```rust,no_run
/// # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
/// # let con = client.get_connection().unwrap();
/// redis::cmd("SET").arg(["my_key", "my_value"].as_slice());
/// redis::cmd("SET").arg("my_key").arg(42i);
/// redis::cmd("SET").arg(&["my_key", "my_value"]);
/// redis::cmd("SET").arg("my_key").arg(42);
/// redis::cmd("SET").arg("my_key").arg(b"my_value");
/// ```
#[inline]
Expand All @@ -164,7 +164,7 @@ impl Cmd {
/// # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
/// # let con = client.get_connection().unwrap();
/// let mut cmd = redis::cmd("SSCAN");
/// let mut iter : redis::Iter<int> = cmd.arg("my_set").cursor_arg(0).iter(&con).unwrap();
/// let mut iter : redis::Iter<isize> = cmd.arg("my_set").cursor_arg(0).iter(&con).unwrap();
/// for x in iter {
/// // do something with the item
/// }
Expand Down Expand Up @@ -207,7 +207,7 @@ impl Cmd {
#[inline]
pub fn query<T: FromRedisValue>(&self, con: &ConnectionLike) -> RedisResult<T> {
let pcmd = self.get_packed_command();
match con.req_packed_command(pcmd.as_slice()) {
match con.req_packed_command(&pcmd) {
Ok(val) => from_redis_value(&val),
Err(e) => Err(e),
}
Expand All @@ -231,7 +231,7 @@ impl Cmd {
pub fn iter<'a, T: FromRedisValue>(&self, con: &'a ConnectionLike)
-> RedisResult<Iter<'a, T>> {
let pcmd = self.get_packed_command();
let rv = try!(con.req_packed_command(pcmd.as_slice()));
let rv = try!(con.req_packed_command(&pcmd));
let mut batch : Vec<T>;
let mut cursor = 0;

Expand Down Expand Up @@ -282,9 +282,9 @@ impl Cmd {
/// # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
/// # let con = client.get_connection().unwrap();
/// let ((k1, k2),) : ((i32, i32),) = redis::pipe()
/// .cmd("SET").arg("key_1").arg(42i).ignore()
/// .cmd("SET").arg("key_2").arg(43i).ignore()
/// .cmd("MGET").arg(["key_1", "key_2"].as_slice()).query(&con).unwrap();
/// .cmd("SET").arg("key_1").arg(42).ignore()
/// .cmd("SET").arg("key_2").arg(43).ignore()
/// .cmd("MGET").arg(&["key_1", "key_2"]).query(&con).unwrap();
/// ```
///
/// As you can see with `cmd` you can start a new command. By default
Expand Down Expand Up @@ -407,8 +407,8 @@ impl Pipeline {
/// # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
/// # let con = client.get_connection().unwrap();
/// let (k1, k2) : (i32, i32) = redis::pipe()
/// .cmd("SET").arg("key_1").arg(42i).ignore()
/// .cmd("SET").arg("key_2").arg(43i).ignore()
/// .cmd("SET").arg("key_1").arg(42).ignore()
/// .cmd("SET").arg("key_2").arg(43).ignore()
/// .cmd("GET").arg("key_1")
/// .cmd("GET").arg("key_2").query(&con).unwrap();
/// ```
Expand Down Expand Up @@ -464,12 +464,13 @@ pub fn cmd<'a>(name: &'a str) -> Cmd {
/// Example:
///
/// ```rust
/// # #![feature(collections)]
/// # use redis::ToRedisArgs;
/// let mut args = vec![];
/// args.push_all("SET".to_redis_args().as_slice());
/// args.push_all("my_key".to_redis_args().as_slice());
/// args.push_all(42i.to_redis_args().as_slice());
/// let cmd = redis::pack_command(args.as_slice());
/// args.push_all(&"SET".to_redis_args());
/// args.push_all(&"my_key".to_redis_args());
/// args.push_all(&42.to_redis_args());
/// let cmd = redis::pack_command(&args);
/// assert_eq!(cmd, b"*3\r\n$3\r\nSET\r\n$6\r\nmy_key\r\n$2\r\n42\r\n".to_vec());
/// ```
pub fn pack_command(args: &[Vec<u8>]) -> Vec<u8> {
Expand Down
6 changes: 3 additions & 3 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ macro_rules! implement_commands {
/// # fn do_something() -> redis::RedisResult<()> {
/// let client = try!(redis::Client::open("redis://127.0.0.1/"));
/// let con = try!(client.get_connection());
/// redis::cmd("SET").arg("my_key").arg(42i).execute(&con);
/// assert_eq!(redis::cmd("GET").arg("my_key").query(&con), Ok(42i));
/// redis::cmd("SET").arg("my_key").arg(42).execute(&con);
/// assert_eq!(redis::cmd("GET").arg("my_key").query(&con), Ok(42));
/// # Ok(()) }
/// ```
///
Expand All @@ -37,7 +37,7 @@ macro_rules! implement_commands {
/// use redis::Commands;
/// let client = try!(redis::Client::open("redis://127.0.0.1/"));
/// let con = try!(client.get_connection());
/// assert_eq!(con.get("my_key"), Ok(42i));
/// assert_eq!(con.get("my_key"), Ok(42));
/// # Ok(()) }
/// ```
pub trait Commands : ConnectionLike+Sized {
Expand Down
14 changes: 7 additions & 7 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn parse_redis_url(input: &str) -> url::ParseResult<url::Url> {
parser.scheme_type_mapper(redis_scheme_type_mapper);
match parser.parse(input) {
Ok(result) => {
if result.scheme.as_slice() != "redis" {
if result.scheme != "redis" {
Err(url::ParseError::InvalidScheme)
} else {
Ok(result)
Expand Down Expand Up @@ -73,15 +73,15 @@ impl<'a> IntoConnectionInfo for &'a str {

impl IntoConnectionInfo for url::Url {
fn into_connection_info(self) -> RedisResult<ConnectionInfo> {
ensure!(self.scheme.as_slice() == "redis",
ensure!(self.scheme == "redis",
fail!((InvalidClientConfig, "URL provided is not a redis URL")));

Ok(ConnectionInfo {
host: unwrap_or!(self.serialize_host(),
fail!((InvalidClientConfig, "Missing hostname"))),
port: self.port().unwrap_or(DEFAULT_PORT),
db: match self.serialize_path().unwrap_or("".to_string())
.as_slice().trim_matches('/') {
.trim_matches('/') {
"" => 0,
path => path.parse::<i64>().unwrap_or(
fail!((InvalidClientConfig, "Invalid database number"))),
Expand Down Expand Up @@ -356,10 +356,10 @@ impl PubSub {
let mut payload;
let mut channel;

if msg_type.as_slice() == "message" {
if msg_type == "message" {
channel = unwrap_or!(iter.next(), continue);
payload = unwrap_or!(iter.next(), continue);
} else if msg_type.as_slice() == "pmessage" {
} else if msg_type == "pmessage" {
pattern = Some(unwrap_or!(iter.next(), continue));
channel = unwrap_or!(iter.next(), continue);
payload = unwrap_or!(iter.next(), continue);
Expand Down Expand Up @@ -453,8 +453,8 @@ impl Msg {
/// # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
/// # let con = client.get_connection().unwrap();
/// let key = "the_key";
/// let (new_val,) : (int,) = try!(redis::transaction(&con, &[key], |pipe| {
/// let old_val : int = try!(con.get(key));
/// let (new_val,) : (isize,) = try!(redis::transaction(&con, &[key], |pipe| {
/// let old_val : isize = try!(con.get(key));
/// pipe
/// .set(key, old_val + 1).ignore()
/// .get(key).query(&con)
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
//!
//! ```rust,no_run
//! fn do_something(con: &redis::Connection) -> redis::RedisResult<()> {
//! let _ : () = try!(redis::cmd("SET").arg("my_key").arg(42i).query(con));
//! let _ : () = try!(redis::cmd("SET").arg("my_key").arg(42).query(con));
//! Ok(())
//! }
//! ```
Expand All @@ -82,7 +82,7 @@
//! use redis::Commands;
//!
//! fn do_something(con: &redis::Connection) -> redis::RedisResult<()> {
//! let _ : () = try!(con.set("my_key", 42i));
//! let _ : () = try!(con.set("my_key", 42));
//! Ok(())
//! }
//! # fn main() {}
Expand Down Expand Up @@ -135,7 +135,7 @@
//! # fn do_something() -> redis::RedisResult<()> {
//! # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
//! # let con = client.get_connection().unwrap();
//! let mut iter : redis::Iter<int> = try!(redis::cmd("SSCAN").arg("my_set")
//! let mut iter : redis::Iter<isize> = try!(redis::cmd("SSCAN").arg("my_set")
//! .cursor_arg(0).iter(&con));
//! for x in iter {
//! // do something with the item
Expand All @@ -160,8 +160,8 @@
//! # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
//! # let con = client.get_connection().unwrap();
//! let (k1, k2) : (i32, i32) = try!(redis::pipe()
//! .cmd("SET").arg("key_1").arg(42i).ignore()
//! .cmd("SET").arg("key_2").arg(43i).ignore()
//! .cmd("SET").arg("key_1").arg(42).ignore()
//! .cmd("SET").arg("key_2").arg(43).ignore()
//! .cmd("GET").arg("key_1")
//! .cmd("GET").arg("key_2").query(&con));
//! # Ok(()) }
Expand All @@ -178,8 +178,8 @@
//! # let con = client.get_connection().unwrap();
//! let (k1, k2) : (i32, i32) = try!(redis::pipe()
//! .atomic()
//! .cmd("SET").arg("key_1").arg(42i).ignore()
//! .cmd("SET").arg("key_2").arg(43i).ignore()
//! .cmd("SET").arg("key_1").arg(42).ignore()
//! .cmd("SET").arg("key_2").arg(43).ignore()
//! .cmd("GET").arg("key_1")
//! .cmd("GET").arg("key_2").query(&con));
//! # Ok(()) }
Expand All @@ -195,8 +195,8 @@
//! # let con = client.get_connection().unwrap();
//! let (k1, k2) : (i32, i32) = try!(redis::pipe()
//! .atomic()
//! .set("key_1", 42i).ignore()
//! .set("key_2", 43i).ignore()
//! .set("key_1", 42).ignore()
//! .set("key_2", 43).ignore()
//! .get("key_1")
//! .get("key_2").query(&con));
//! # Ok(()) }
Expand All @@ -214,8 +214,8 @@
//! # let client = redis::Client::open("redis://127.0.0.1/").unwrap();
//! # let con = client.get_connection().unwrap();
//! let key = "the_key";
//! let (new_val,) : (int,) = try!(redis::transaction(&con, &[key], |pipe| {
//! let old_val : int = try!(con.get(key));
//! let (new_val,) : (isize,) = try!(redis::transaction(&con, &[key], |pipe| {
//! let old_val : isize = try!(con.get(key));
//! pipe
//! .set(key, old_val + 1).ignore()
//! .get(key).query(&con)
Expand Down Expand Up @@ -265,14 +265,14 @@
//! let script = redis::Script::new(r"
//! return tonumber(ARGV[1]) + tonumber(ARGV[2]);
//! ");
//! let result : int = try!(script.arg(1i).arg(2i).invoke(&con));
//! let result : isize = try!(script.arg(1).arg(2).invoke(&con));
//! assert_eq!(result, 3);
//! # Ok(()) }
//! ```

#![deny(non_camel_case_types)]

#![feature(collections, core, io, net, plugin)]
#![feature(collections, core)]

extern crate url;
extern crate rustc_serialize as serialize;
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ impl<'a, T: Read> Parser<T> {

fn read_int_line(&mut self) -> RedisResult<i64> {
let line = try!(self.read_string_line());
match line.as_slice().trim().parse::<i64>() {
match line.trim().parse::<i64>() {
Err(_) => fail!((ResponseError, "Expected integer, got garbage")),
Ok(value) => Ok(value)
}
}

fn parse_status(&mut self) -> RedisResult<Value> {
let line = try!(self.read_string_line());
if line.as_slice() == "OK" {
if line == "OK" {
Ok(Value::Okay)
} else {
Ok(Value::Status(line))
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'a, T: Read> Parser<T> {

fn parse_error(&mut self) -> RedisResult<Value> {
let line = try!(self.read_string_line());
let mut pieces = line.as_slice().splitn(1, ' ');
let mut pieces = line.splitn(1, ' ');
let kind = match pieces.next().unwrap() {
"ERR" => ResponseError,
"EXECABORT" => ExecAbortError,
Expand Down
6 changes: 3 additions & 3 deletions src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct Script {
/// let script = redis::Script::new(r"
/// return tonumber(ARGV[1]) + tonumber(ARGV[2]);
/// ");
/// let result = script.arg(1i).arg(2i).invoke(&con);
/// assert_eq!(result, Ok(3i));
/// let result = script.arg(1).arg(2).invoke(&con);
/// assert_eq!(result, Ok(3));
/// ```
impl Script {

Expand All @@ -39,7 +39,7 @@ impl Script {

/// Returns the script's SHA1 hash in hexadecimal format.
pub fn get_hash(&self) -> &str {
self.hash.as_slice()
&self.hash
}

/// Creates a script invocation object with a key filled in.
Expand Down
Loading

0 comments on commit 88bc1fd

Please sign in to comment.