Skip to content

Commit 705f9f9

Browse files
committed
Remove a bunch of slice sugar usage
1 parent cfe37fa commit 705f9f9

2 files changed

Lines changed: 39 additions & 39 deletions

File tree

src/lib.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ impl IntoConnectParams for Url {
174174
..
175175
} = self;
176176

177-
let maybe_path = try!(url::decode_component(host[]).map_err(ConnectError::InvalidUrl));
178-
let target = if maybe_path[].starts_with("/") {
177+
let maybe_path = try!(url::decode_component(&*host).map_err(ConnectError::InvalidUrl));
178+
let target = if maybe_path.starts_with("/") {
179179
ConnectTarget::Unix(Path::new(maybe_path))
180180
} else {
181181
ConnectTarget::Tcp(host)
@@ -407,7 +407,7 @@ impl InnerConnection {
407407

408408
try!(conn.write_messages(&[StartupMessage {
409409
version: message::PROTOCOL_VERSION,
410-
parameters: options[]
410+
parameters: &*options
411411
}]));
412412

413413
try!(conn.handle_auth(user));
@@ -481,21 +481,21 @@ impl InnerConnection {
481481
AuthenticationCleartextPassword => {
482482
let pass = try!(user.password.ok_or(ConnectError::MissingPassword));
483483
try!(self.write_messages(&[PasswordMessage {
484-
password: pass[],
484+
password: &*pass,
485485
}]));
486486
}
487487
AuthenticationMD5Password { salt } => {
488488
let pass = try!(user.password.ok_or(ConnectError::MissingPassword));
489489
let mut hasher = Hasher::new(HashType::MD5);
490490
hasher.update(pass.as_bytes());
491491
hasher.update(user.user.as_bytes());
492-
let output = hasher.finalize()[].to_hex();
492+
let output = hasher.finalize().to_hex();
493493
let mut hasher = Hasher::new(HashType::MD5);
494494
hasher.update(output.as_bytes());
495495
hasher.update(&salt);
496-
let output = format!("md5{}", hasher.finalize()[].to_hex());
496+
let output = format!("md5{}", hasher.finalize().to_hex());
497497
try!(self.write_messages(&[PasswordMessage {
498-
password: output[]
498+
password: &*output
499499
}]));
500500
}
501501
AuthenticationKerberosV5
@@ -521,13 +521,13 @@ impl InnerConnection {
521521
-> Result<(Vec<Type>, Vec<ResultDescription>)> {
522522
try!(self.write_messages(&[
523523
Parse {
524-
name: stmt_name[],
524+
name: &*stmt_name,
525525
query: query,
526526
param_types: &[]
527527
},
528528
Describe {
529529
variant: b'S',
530-
name: stmt_name[],
530+
name: &*stmt_name,
531531
},
532532
Sync]));
533533

@@ -599,7 +599,7 @@ impl InnerConnection {
599599
let _ = util::comma_join(&mut query, rows.iter().cloned());
600600
let _ = write!(&mut query, " FROM {}", table);
601601
let query = String::from_utf8(query).unwrap();
602-
let (_, result_desc) = try!(self.raw_prepare("", query[]));
602+
let (_, result_desc) = try!(self.raw_prepare("", &*query));
603603
let column_types = result_desc.into_iter().map(|desc| desc.ty).collect();
604604

605605
let mut query = vec![];
@@ -608,7 +608,7 @@ impl InnerConnection {
608608
let _ = write!(&mut query, ") FROM STDIN WITH (FORMAT binary)");
609609
let query = String::from_utf8(query).unwrap();
610610
let stmt_name = self.make_stmt_name();
611-
try!(self.raw_prepare(&*stmt_name, query[]));
611+
try!(self.raw_prepare(&*stmt_name, &*query));
612612

613613
Ok(CopyInStatement {
614614
conn: conn,
@@ -648,8 +648,8 @@ impl InnerConnection {
648648
if let Some(name) = self.unknown_types.get(&oid) {
649649
return Ok(name.clone());
650650
}
651-
let name = try!(self.quick_query(format!("SELECT typname FROM pg_type \
652-
WHERE oid={}", oid)[]))
651+
let name = try!(self.quick_query(&*format!("SELECT typname FROM pg_type \
652+
WHERE oid={}", oid)))
653653
.into_iter().next().unwrap().into_iter().next().unwrap().unwrap();
654654
self.unknown_types.insert(oid, name.clone());
655655
Ok(name)
@@ -680,7 +680,7 @@ impl InnerConnection {
680680
ReadyForQuery { .. } => break,
681681
DataRow { row } => {
682682
result.push(row.into_iter().map(|opt| {
683-
opt.map(|b| String::from_utf8_lossy(b[]).into_string())
683+
opt.map(|b| String::from_utf8_lossy(&*b).into_string())
684684
}).collect());
685685
}
686686
CopyInResponse { .. } => {
@@ -1148,7 +1148,7 @@ impl<'conn> Statement<'conn> {
11481148
fn finish_inner(&mut self) -> Result<()> {
11491149
let mut conn = self.conn.conn.borrow_mut();
11501150
check_desync!(conn);
1151-
conn.close_statement(self.name[], b'S')
1151+
conn.close_statement(&*self.name, b'S')
11521152
}
11531153

11541154
fn inner_execute(&self, portal_name: &str, row_limit: i32, params: &[&ToSql]) -> Result<()> {
@@ -1167,9 +1167,9 @@ impl<'conn> Statement<'conn> {
11671167
try!(conn.write_messages(&[
11681168
Bind {
11691169
portal: portal_name,
1170-
statement: self.name[],
1170+
statement: &*self.name,
11711171
formats: &[1],
1172-
values: values[],
1172+
values: &*values,
11731173
result_formats: &[1]
11741174
},
11751175
Execute {
@@ -1196,7 +1196,7 @@ impl<'conn> Statement<'conn> {
11961196
self.next_portal_id.set(id + 1);
11971197
let portal_name = format!("{}p{}", self.name, id);
11981198

1199-
try!(self.inner_execute(portal_name[], row_limit, params));
1199+
try!(self.inner_execute(&*portal_name, row_limit, params));
12001200

12011201
let mut result = Rows {
12021202
stmt: self,
@@ -1213,12 +1213,12 @@ impl<'conn> Statement<'conn> {
12131213

12141214
/// Returns a slice containing the expected parameter types.
12151215
pub fn param_types(&self) -> &[Type] {
1216-
self.param_types[]
1216+
&*self.param_types
12171217
}
12181218

12191219
/// Returns a slice describing the columns of the result of the query.
12201220
pub fn result_descriptions(&self) -> &[ResultDescription] {
1221-
self.result_desc[]
1221+
&*self.result_desc
12221222
}
12231223

12241224
/// Executes the prepared statement, returning the number of rows modified.
@@ -1342,7 +1342,7 @@ impl<'stmt> Rows<'stmt> {
13421342
fn finish_inner(&mut self) -> Result<()> {
13431343
let mut conn = self.stmt.conn.conn.borrow_mut();
13441344
check_desync!(conn);
1345-
conn.close_statement(self.name[], b'P')
1345+
conn.close_statement(&*self.name, b'P')
13461346
}
13471347

13481348
fn read_rows(&mut self) -> Result<()> {
@@ -1381,7 +1381,7 @@ impl<'stmt> Rows<'stmt> {
13811381
fn execute(&mut self) -> Result<()> {
13821382
try!(self.stmt.conn.write_messages(&[
13831383
Execute {
1384-
portal: self.name[],
1384+
portal: &*self.name,
13851385
max_rows: self.row_limit
13861386
},
13871387
Sync]));
@@ -1512,7 +1512,7 @@ impl RowIndex for uint {
15121512
impl<'a> RowIndex for &'a str {
15131513
#[inline]
15141514
fn idx(&self, stmt: &Statement) -> Option<uint> {
1515-
stmt.result_descriptions().iter().position(|d| d.name[] == *self)
1515+
stmt.result_descriptions().iter().position(|d| &*d.name == *self)
15161516
}
15171517
}
15181518

@@ -1563,12 +1563,12 @@ impl<'a> CopyInStatement<'a> {
15631563
fn finish_inner(&mut self) -> Result<()> {
15641564
let mut conn = self.conn.conn.borrow_mut();
15651565
check_desync!(conn);
1566-
conn.close_statement(self.name[], b'S')
1566+
conn.close_statement(&*self.name, b'S')
15671567
}
15681568

15691569
/// Returns a slice containing the expected column types.
15701570
pub fn column_types(&self) -> &[Type] {
1571-
self.column_types[]
1571+
&*self.column_types
15721572
}
15731573

15741574
/// Executes the prepared statement.
@@ -1584,7 +1584,7 @@ impl<'a> CopyInStatement<'a> {
15841584
try!(conn.write_messages(&[
15851585
Bind {
15861586
portal: "",
1587-
statement: self.name[],
1587+
statement: &*self.name,
15881588
formats: &[],
15891589
values: &[],
15901590
result_formats: &[]
@@ -1633,13 +1633,13 @@ impl<'a> CopyInStatement<'a> {
16331633
}
16341634
Ok(Some(val)) => {
16351635
let _ = buf.write_be_i32(val.len() as i32);
1636-
let _ = buf.write(val[]);
1636+
let _ = buf.write(&*val);
16371637
}
16381638
Err(err) => {
16391639
// FIXME this is not the right way to handle this
16401640
try_desync!(conn, conn.stream.write_message(
16411641
&CopyFail {
1642-
message: err.to_string()[],
1642+
message: &*err.to_string(),
16431643
}));
16441644
break 'l;
16451645
}
@@ -1658,15 +1658,15 @@ impl<'a> CopyInStatement<'a> {
16581658

16591659
try_desync!(conn, conn.stream.write_message(
16601660
&CopyData {
1661-
data: buf[]
1661+
data: &*buf
16621662
}));
16631663
buf.clear();
16641664
}
16651665

16661666
let _ = buf.write_be_i16(-1);
16671667
try!(conn.write_messages(&[
16681668
CopyData {
1669-
data: buf[],
1669+
data: &*buf,
16701670
},
16711671
CopyDone,
16721672
Sync]));

src/types/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ macro_rules! from_raw_from_impl(
110110
use std::io::BufReader;
111111
use types::RawFromSql;
112112

113-
let mut reader = BufReader::new(buf[]);
113+
let mut reader = BufReader::new(&**buf);
114114
RawFromSql::raw_from_sql(&mut reader)
115115
} $(, $a)*)
116116
)
@@ -126,7 +126,7 @@ macro_rules! from_array_impl(
126126
use types::array::{ArrayBase, DimensionInfo};
127127
use Error;
128128

129-
let mut rdr = BufReader::new(buf[]);
129+
let mut rdr = BufReader::new(&**buf);
130130

131131
let ndim = try!(rdr.read_be_i32()) as uint;
132132
let _has_null = try!(rdr.read_be_i32()) == 1;
@@ -202,7 +202,7 @@ macro_rules! to_range_impl(
202202
let mut inner_buf = vec![];
203203
try!(bound.value.raw_to_sql(&mut inner_buf));
204204
try!(buf.write_be_u32(inner_buf.len() as u32));
205-
try!(buf.write(inner_buf[]));
205+
try!(buf.write(&*inner_buf));
206206
}
207207
Ok(())
208208
}
@@ -289,7 +289,7 @@ macro_rules! to_array_impl(
289289
let mut inner_buf = vec![];
290290
try!(val.raw_to_sql(&mut inner_buf));
291291
try!(buf.write_be_i32(inner_buf.len() as i32));
292-
try!(buf.write(inner_buf[]));
292+
try!(buf.write(&*inner_buf));
293293
}
294294
None => try!(buf.write_be_i32(-1))
295295
}
@@ -569,13 +569,13 @@ impl FromSql for Option<HashMap<String, Option<String>>> {
569569
fn from_sql(ty: &Type, raw: &Option<Vec<u8>>)
570570
-> Result<Option<HashMap<String, Option<String>>>> {
571571
match *ty {
572-
Type::Unknown { ref name, .. } if "hstore" == name[] => {}
572+
Type::Unknown { ref name, .. } if "hstore" == &**name => {}
573573
_ => return Err(Error::WrongType(ty.clone()))
574574
}
575575

576576
match *raw {
577577
Some(ref buf) => {
578-
let mut rdr = BufReader::new(buf[]);
578+
let mut rdr = BufReader::new(&**buf);
579579
let mut map = HashMap::new();
580580

581581
let count = try!(rdr.read_be_i32());
@@ -642,7 +642,7 @@ impl RawToSql for bool {
642642

643643
impl RawToSql for Vec<u8> {
644644
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> Result<()> {
645-
Ok(try!(w.write(self[])))
645+
Ok(try!(w.write(&**self)))
646646
}
647647
}
648648

@@ -715,7 +715,7 @@ to_array_impl!(JsonArray, json::Json)
715715
impl ToSql for HashMap<String, Option<String>> {
716716
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
717717
match *ty {
718-
Type::Unknown { ref name, .. } if "hstore" == name[] => {}
718+
Type::Unknown { ref name, .. } if "hstore" == &**name => {}
719719
_ => return Err(Error::WrongType(ty.clone()))
720720
}
721721

@@ -743,7 +743,7 @@ impl ToSql for HashMap<String, Option<String>> {
743743
impl ToSql for Option<HashMap<String, Option<String>>> {
744744
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
745745
match *ty {
746-
Type::Unknown { ref name, .. } if "hstore" == name[] => {}
746+
Type::Unknown { ref name, .. } if "hstore" == &**name => {}
747747
_ => return Err(Error::WrongType(ty.clone()))
748748
}
749749

0 commit comments

Comments
 (0)