Skip to content

Commit e5ed2ba

Browse files
committed
Use new slice syntax
1 parent dd40522 commit e5ed2ba

9 files changed

Lines changed: 67 additions & 68 deletions

File tree

src/error.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ make_errors!(
205205
"38003" => ProhibitedSqlStatementAttemptedExternalRoutine,
206206
"38004" => ReadingSqlDataNotPermittedExternalRoutine,
207207

208-
209208
// Class 39 — External Routine Invocation Exception
210209
"39000" => ExternalRoutineInvocationException,
211210
"39001" => InvalidSqlstateReturned,
@@ -484,15 +483,15 @@ impl PostgresDbError {
484483
let mut map: HashMap<_, _> = fields.into_iter().collect();
485484
Ok(PostgresDbError {
486485
severity: try!(map.pop(&b'S').ok_or(())),
487-
code: PostgresSqlState::from_code(try!(map.pop(&b'C').ok_or(())).as_slice()),
486+
code: PostgresSqlState::from_code(try!(map.pop(&b'C').ok_or(()))[]),
488487
message: try!(map.pop(&b'M').ok_or(())),
489488
detail: map.pop(&b'D'),
490489
hint: map.pop(&b'H'),
491490
position: match map.pop(&b'P') {
492-
Some(pos) => Some(Position(try!(from_str(pos.as_slice()).ok_or(())))),
491+
Some(pos) => Some(Position(try!(from_str(pos[]).ok_or(())))),
493492
None => match map.pop(&b'p') {
494493
Some(pos) => Some(InternalPosition {
495-
position: try!(from_str(pos.as_slice()).ok_or(())),
494+
position: try!(from_str(pos[]).ok_or(())),
496495
query: try!(map.pop(&b'q').ok_or(()))
497496
}),
498497
None => None
@@ -505,7 +504,7 @@ impl PostgresDbError {
505504
datatype: map.pop(&b'd'),
506505
constraint: map.pop(&b'n'),
507506
file: try!(map.pop(&b'F').ok_or(())),
508-
line: try!(map.pop(&b'L').and_then(|l| from_str(l.as_slice())).ok_or(())),
507+
line: try!(map.pop(&b'L').and_then(|l| from_str(l[])).ok_or(())),
509508
routine: map.pop(&b'R').unwrap()
510509
})
511510
}

src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn open_socket(params: &PostgresConnectParams)
8686
let port = params.port.unwrap_or(DEFAULT_PORT);
8787
let socket = match params.target {
8888
TargetTcp(ref host) =>
89-
tcp::TcpStream::connect(host.as_slice(), port).map(|s| TcpStream(s)),
89+
tcp::TcpStream::connect(host[], port).map(|s| TcpStream(s)),
9090
TargetUnix(ref path) => {
9191
let mut path = path.clone();
9292
path.push(format!(".s.PGSQL.{}", port));

src/lib.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ impl IntoConnectParams for Url {
224224
..
225225
} = self;
226226

227-
let maybe_path = try!(url::decode_component(host.as_slice()).map_err(InvalidUrl));
228-
let target = if maybe_path.as_slice().starts_with("/") {
227+
let maybe_path = try!(url::decode_component(host[]).map_err(InvalidUrl));
228+
let target = if maybe_path[].starts_with("/") {
229229
TargetUnix(Path::new(maybe_path))
230230
} else {
231231
TargetTcp(host)
@@ -238,7 +238,7 @@ impl IntoConnectParams for Url {
238238

239239
let database = if !path.is_empty() {
240240
// path contains the leading /
241-
let (_, path) = path.as_slice().slice_shift_char();
241+
let (_, path) = path[].slice_shift_char();
242242
Some(path.to_string())
243243
} else {
244244
None
@@ -413,7 +413,7 @@ impl InnerPostgresConnection {
413413

414414
try_pg_conn!(conn.write_messages([StartupMessage {
415415
version: message::PROTOCOL_VERSION,
416-
parameters: options.as_slice()
416+
parameters: options[]
417417
}]));
418418

419419
try!(conn.handle_auth(user));
@@ -476,7 +476,7 @@ impl InnerPostgresConnection {
476476
None => return Err(MissingPassword)
477477
};
478478
try_pg_conn!(self.write_messages([PasswordMessage {
479-
password: pass.as_slice(),
479+
password: pass[],
480480
}]));
481481
}
482482
AuthenticationMD5Password { salt } => {
@@ -487,14 +487,14 @@ impl InnerPostgresConnection {
487487
let hasher = Hasher::new(MD5);
488488
hasher.update(pass.as_bytes());
489489
hasher.update(user.user.as_bytes());
490-
let output = hasher.final().as_slice().to_hex();
490+
let output = hasher.final()[].to_hex();
491491
let hasher = Hasher::new(MD5);
492492
hasher.update(output.as_bytes());
493493
hasher.update(salt);
494494
let output = format!("md5{}",
495-
hasher.final().as_slice().to_hex());
495+
hasher.final()[].to_hex());
496496
try_pg_conn!(self.write_messages([PasswordMessage {
497-
password: output.as_slice()
497+
password: output[]
498498
}]));
499499
}
500500
AuthenticationKerberosV5
@@ -530,13 +530,13 @@ impl InnerPostgresConnection {
530530

531531
try_pg!(self.write_messages([
532532
Parse {
533-
name: stmt_name.as_slice(),
533+
name: stmt_name[],
534534
query: query,
535535
param_types: []
536536
},
537537
Describe {
538538
variant: b'S',
539-
name: stmt_name.as_slice(),
539+
name: stmt_name[],
540540
},
541541
Sync]));
542542

@@ -598,17 +598,17 @@ impl InnerPostgresConnection {
598598
let _ = util::comma_join(&mut query, rows.iter().map(|&e| e));
599599
let _ = write!(query, " FROM {}", table);
600600
let query = String::from_utf8(query.unwrap()).unwrap();
601-
let (stmt_name, _, result_desc) = try!(self.raw_prepare(query.as_slice()));
601+
let (stmt_name, _, result_desc) = try!(self.raw_prepare(query[]));
602602

603603
let column_types = result_desc.iter().map(|desc| desc.ty.clone()).collect();
604-
try!(self.close_statement(stmt_name.as_slice()));
604+
try!(self.close_statement(stmt_name[]));
605605

606606
let mut query = MemWriter::new();
607607
let _ = write!(query, "COPY {} (", table);
608608
let _ = util::comma_join(&mut query, rows.iter().map(|&e| e));
609609
let _ = write!(query, ") FROM STDIN WITH (FORMAT binary)");
610610
let query = String::from_utf8(query.unwrap()).unwrap();
611-
let (stmt_name, _, _) = try!(self.raw_prepare(query.as_slice()));
611+
let (stmt_name, _, _) = try!(self.raw_prepare(query[]));
612612

613613
Ok(PostgresCopyInStatement {
614614
conn: conn,
@@ -656,7 +656,7 @@ impl InnerPostgresConnection {
656656
None => {}
657657
}
658658
let name = try!(self.quick_query(format!("SELECT typname FROM pg_type \
659-
WHERE oid={}", oid).as_slice()))
659+
WHERE oid={}", oid)[]))
660660
.into_iter().next().unwrap().into_iter().next().unwrap().unwrap();
661661
self.unknown_types.insert(oid, name.clone());
662662
Ok(name)
@@ -687,7 +687,7 @@ impl InnerPostgresConnection {
687687
ReadyForQuery { .. } => break,
688688
DataRow { row } => {
689689
result.push(row.into_iter().map(|opt| {
690-
opt.map(|b| String::from_utf8_lossy(b.as_slice()).into_string())
690+
opt.map(|b| String::from_utf8_lossy(b[]).into_string())
691691
}).collect());
692692
}
693693
ErrorResponse { fields } => {
@@ -1149,7 +1149,7 @@ impl<'conn> PostgresStatement<'conn> {
11491149
fn finish_inner(&mut self) -> PostgresResult<()> {
11501150
let mut conn = self.conn.conn.borrow_mut();
11511151
check_desync!(conn);
1152-
conn.close_statement(self.name.as_slice())
1152+
conn.close_statement(self.name[])
11531153
}
11541154

11551155
fn inner_execute(&self, portal_name: &str, row_limit: i32, params: &[&ToSql])
@@ -1170,9 +1170,9 @@ impl<'conn> PostgresStatement<'conn> {
11701170
try_pg!(conn.write_messages([
11711171
Bind {
11721172
portal: portal_name,
1173-
statement: self.name.as_slice(),
1173+
statement: self.name[],
11741174
formats: [1],
1175-
values: values.as_slice(),
1175+
values: values[],
11761176
result_formats: [1]
11771177
},
11781178
Execute {
@@ -1200,7 +1200,7 @@ impl<'conn> PostgresStatement<'conn> {
12001200
self.next_portal_id.set(id + 1);
12011201
let portal_name = format!("{}p{}", self.name, id);
12021202

1203-
try!(self.inner_execute(portal_name.as_slice(), row_limit, params));
1203+
try!(self.inner_execute(portal_name[], row_limit, params));
12041204

12051205
let mut result = PostgresRows {
12061206
stmt: self,
@@ -1217,12 +1217,12 @@ impl<'conn> PostgresStatement<'conn> {
12171217

12181218
/// Returns a slice containing the expected parameter types.
12191219
pub fn param_types(&self) -> &[PostgresType] {
1220-
self.param_types.as_slice()
1220+
self.param_types[]
12211221
}
12221222

12231223
/// Returns a slice describing the columns of the result of the query.
12241224
pub fn result_descriptions(&self) -> &[ResultDescription] {
1225-
self.result_desc.as_slice()
1225+
self.result_desc[]
12261226
}
12271227

12281228
/// Executes the prepared statement, returning the number of rows modified.
@@ -1349,7 +1349,7 @@ impl<'stmt> PostgresRows<'stmt> {
13491349
try_pg!(conn.write_messages([
13501350
Close {
13511351
variant: b'P',
1352-
name: self.name.as_slice()
1352+
name: self.name[]
13531353
},
13541354
Sync]));
13551355

@@ -1404,7 +1404,7 @@ impl<'stmt> PostgresRows<'stmt> {
14041404
fn execute(&mut self) -> PostgresResult<()> {
14051405
try_pg!(self.stmt.conn.write_messages([
14061406
Execute {
1407-
portal: self.name.as_slice(),
1407+
portal: self.name[],
14081408
max_rows: self.row_limit
14091409
},
14101410
Sync]));
@@ -1535,7 +1535,7 @@ impl RowIndex for uint {
15351535
impl<'a> RowIndex for &'a str {
15361536
#[inline]
15371537
fn idx(&self, stmt: &PostgresStatement) -> Option<uint> {
1538-
stmt.result_descriptions().iter().position(|d| d.name.as_slice() == *self)
1538+
stmt.result_descriptions().iter().position(|d| d.name[] == *self)
15391539
}
15401540
}
15411541

@@ -1587,12 +1587,12 @@ impl<'a> PostgresCopyInStatement<'a> {
15871587
fn finish_inner(&mut self) -> PostgresResult<()> {
15881588
let mut conn = self.conn.conn.borrow_mut();
15891589
check_desync!(conn);
1590-
conn.close_statement(self.name.as_slice())
1590+
conn.close_statement(self.name[])
15911591
}
15921592

15931593
/// Returns a slice containing the expected column types.
15941594
pub fn column_types(&self) -> &[PostgresType] {
1595-
self.column_types.as_slice()
1595+
self.column_types[]
15961596
}
15971597

15981598
/// Executes the prepared statement.
@@ -1608,7 +1608,7 @@ impl<'a> PostgresCopyInStatement<'a> {
16081608
try_pg!(conn.write_messages([
16091609
Bind {
16101610
portal: "",
1611-
statement: self.name.as_slice(),
1611+
statement: self.name[],
16121612
formats: [],
16131613
values: [],
16141614
result_formats: []
@@ -1657,7 +1657,7 @@ impl<'a> PostgresCopyInStatement<'a> {
16571657
}
16581658
Some(val) => {
16591659
let _ = buf.write_be_i32(val.len() as i32);
1660-
let _ = buf.write(val.as_slice());
1660+
let _ = buf.write(val[]);
16611661
}
16621662
}
16631663
}
@@ -1674,15 +1674,15 @@ impl<'a> PostgresCopyInStatement<'a> {
16741674

16751675
try_pg_desync!(conn, conn.stream.write_message(
16761676
&CopyData {
1677-
data: buf.unwrap().as_slice()
1677+
data: buf.unwrap()[]
16781678
}));
16791679
buf = MemWriter::new();
16801680
}
16811681

16821682
let _ = buf.write_be_i16(-1);
16831683
try_pg!(conn.write_messages([
16841684
CopyData {
1685-
data: buf.unwrap().as_slice(),
1685+
data: buf.unwrap()[],
16861686
},
16871687
CopyDone,
16881688
Sync]));

src/message.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<W: Writer> WriteMessage for W {
168168
}
169169
Some(ref value) => {
170170
try!(buf.write_be_i32(value.len() as i32));
171-
try!(buf.write(value.as_slice()));
171+
try!(buf.write(value[]));
172172
}
173173
}
174174
}
@@ -229,8 +229,8 @@ impl<W: Writer> WriteMessage for W {
229229
StartupMessage { version, parameters } => {
230230
try!(buf.write_be_u32(version));
231231
for &(ref k, ref v) in parameters.iter() {
232-
try!(buf.write_cstr(k.as_slice()));
233-
try!(buf.write_cstr(v.as_slice()));
232+
try!(buf.write_cstr(k[]));
233+
try!(buf.write_cstr(v[]));
234234
}
235235
try!(buf.write_u8(0));
236236
}
@@ -251,7 +251,7 @@ impl<W: Writer> WriteMessage for W {
251251
let buf = buf.unwrap();
252252
// add size of length value
253253
try!(self.write_be_i32((buf.len() + mem::size_of::<i32>()) as i32));
254-
try!(self.write(buf.as_slice()));
254+
try!(self.write(buf[]));
255255

256256
Ok(())
257257
}

src/types/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<T> ArrayBase<T> {
152152

153153
impl<T> Array<T> for ArrayBase<T> {
154154
fn dimension_info<'a>(&'a self) -> &'a [DimensionInfo] {
155-
self.info.as_slice()
155+
self.info[]
156156
}
157157

158158
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T> {
@@ -220,7 +220,7 @@ impl<'parent, T> Array<T> for ArraySlice<'parent, T> {
220220
MutSliceParent(p) => p.dimension_info(),
221221
BaseParent(p) => p.dimension_info()
222222
};
223-
info.slice_from(1)
223+
info[1..]
224224
}
225225

226226
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T> {
@@ -272,7 +272,7 @@ impl<'parent, T> Array<T> for MutArraySlice<'parent, T> {
272272
MutBaseParent(ref p) => mem::transmute(p.dimension_info()),
273273
}
274274
};
275-
info.slice_from(1)
275+
info[1..]
276276
}
277277

278278
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T> {

0 commit comments

Comments
 (0)