Use slicing syntax instead of .as_slice()
This commit is contained in:
parent
3022d7301a
commit
5dd077969c
@ -681,7 +681,7 @@ fn test_encoder() {
|
||||
log.encode(&mut encoder).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -780,7 +780,7 @@ fn test_serializer_my_mem_writer0() {
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -811,7 +811,7 @@ fn test_serializer_my_mem_writer1() {
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1011,7 +1011,7 @@ fn test_manual_serialize_vec_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1036,7 +1036,7 @@ fn test_manual_serialize_vec_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1062,7 +1062,7 @@ fn test_manual_serialize_my_mem_writer0_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1088,7 +1088,7 @@ fn test_manual_serialize_my_mem_writer0_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1114,7 +1114,7 @@ fn test_manual_serialize_my_mem_writer1_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1140,7 +1140,7 @@ fn test_manual_serialize_my_mem_writer1_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1189,7 +1189,7 @@ fn test_direct_vec() {
|
||||
direct(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1214,7 +1214,7 @@ fn test_direct_my_mem_writer0() {
|
||||
direct(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1240,7 +1240,7 @@ fn test_direct_my_mem_writer1() {
|
||||
direct(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1291,7 +1291,7 @@ fn test_deserializer() {
|
||||
|
||||
#[inline]
|
||||
fn manual_reader_ignore<R: Reader>(rdr: &mut R, buf: &mut [u8], key: &[u8]) {
|
||||
let buf = buf.slice_mut(0, key.len());
|
||||
let buf = &mut buf[0..key.len()];
|
||||
rdr.read(buf).unwrap();
|
||||
assert_eq!(buf, key);
|
||||
}
|
||||
@ -1350,7 +1350,7 @@ fn manual_reader_string<R: Reader>(rdr: &mut R, buf: &mut [u8], key: &[u8]) -> S
|
||||
let b = rdr.read_byte().unwrap();
|
||||
assert!(b == b',' || b == b']' || b == b'}');
|
||||
|
||||
String::from_utf8(buf.slice_to(idx).to_vec()).unwrap()
|
||||
String::from_utf8(buf[..idx].to_vec()).unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -1432,7 +1432,7 @@ fn manual_reader_deserialize<R: Reader>(rdr: &mut R) -> Log {
|
||||
|
||||
#[inline]
|
||||
fn manual_iter_ignore<R: Iterator<Item=u8>>(mut rdr: R, buf: &mut [u8], key: &[u8]) {
|
||||
let buf = buf.slice_mut(0, key.len());
|
||||
let buf = &mut buf[0..key.len()];
|
||||
|
||||
for idx in range(0, key.len()) {
|
||||
buf[idx] = rdr.next().unwrap();
|
||||
@ -1494,7 +1494,7 @@ fn manual_iter_string<R: Iterator<Item=u8>>(mut rdr: R, buf: &mut [u8], key: &[u
|
||||
let b = rdr.next().unwrap();
|
||||
assert!(b == b',' || b == b']' || b == b'}');
|
||||
|
||||
String::from_utf8(buf.slice_to(idx).to_vec()).unwrap()
|
||||
String::from_utf8(buf[..idx].to_vec()).unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -989,7 +989,7 @@ fn test_encoder() {
|
||||
log.encode(&mut encoder).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(wr.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1039,7 +1039,7 @@ fn test_serializer_vec() {
|
||||
serializer.visit(&log).unwrap();
|
||||
|
||||
let json = serializer.into_inner();
|
||||
assert_eq!(json.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&json[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1089,7 +1089,7 @@ fn test_serializer_my_mem_writer0() {
|
||||
let _json = serializer.into_inner();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1121,7 +1121,7 @@ fn test_serializer_my_mem_writer1() {
|
||||
let _json = serializer.into_inner();
|
||||
}
|
||||
|
||||
assert_eq!(wr.buf.as_slice(), JSON_STR.as_bytes());
|
||||
assert_eq!(&wr.buf[], JSON_STR.as_bytes());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1321,7 +1321,7 @@ fn test_manual_serialize_vec_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1346,7 +1346,7 @@ fn test_manual_serialize_vec_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1372,7 +1372,7 @@ fn test_manual_serialize_my_mem_writer0_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1398,7 +1398,7 @@ fn test_manual_serialize_my_mem_writer0_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1424,7 +1424,7 @@ fn test_manual_serialize_my_mem_writer1_no_escape() {
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
@ -1450,7 +1450,7 @@ fn test_manual_serialize_my_mem_writer1_escape() {
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
|
||||
let json = String::from_utf8(wr.buf).unwrap();
|
||||
assert_eq!(JSON_STR, json.as_slice());
|
||||
assert_eq!(JSON_STR, &json[]);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -402,7 +402,7 @@ fn deserialize_struct_from_map(
|
||||
) -> P<ast::Expr> {
|
||||
let fields = match *fields {
|
||||
Unnamed(_) => fail!(),
|
||||
Named(ref fields) => fields.as_slice(),
|
||||
Named(ref fields) => &fields[],
|
||||
};
|
||||
|
||||
// Declare each field.
|
||||
|
@ -352,7 +352,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
|
||||
let buf = &mut [0; 4];
|
||||
let len = c.encode_utf8(buf).unwrap_or(0);
|
||||
self.buf.extend(buf.slice_to(len).iter().map(|b| *b));
|
||||
self.buf.extend(buf[..len].iter().map(|b| *b));
|
||||
}
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::InvalidEscape));
|
||||
|
@ -206,7 +206,7 @@ pub fn escape_bytes<W: io::Writer>(wr: &mut W, bytes: &[u8]) -> Result<(), IoErr
|
||||
};
|
||||
|
||||
if start < i {
|
||||
try!(wr.write(bytes.slice(start, i)));
|
||||
try!(wr.write(&bytes[start..i]));
|
||||
}
|
||||
|
||||
try!(wr.write_str(escaped));
|
||||
@ -215,7 +215,7 @@ pub fn escape_bytes<W: io::Writer>(wr: &mut W, bytes: &[u8]) -> Result<(), IoErr
|
||||
}
|
||||
|
||||
if start != bytes.len() {
|
||||
try!(wr.write(bytes.slice_from(start)));
|
||||
try!(wr.write(&bytes[start..]));
|
||||
}
|
||||
|
||||
wr.write_str("\"")
|
||||
|
@ -239,7 +239,7 @@ impl Serialize for String {
|
||||
fn visit<
|
||||
V: Visitor,
|
||||
>(&self, visitor: &mut V) -> Result<V::Value, V::Error> {
|
||||
self.as_slice().visit(visitor)
|
||||
(&self[]).visit(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ impl<
|
||||
fn visit<
|
||||
V: Visitor,
|
||||
>(&self, visitor: &mut V) -> Result<V::Value, V::Error> {
|
||||
self.as_slice().visit(visitor)
|
||||
(&self[]).visit(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ fn deserialize_struct(
|
||||
|
||||
let fields = match *fields {
|
||||
Unnamed(_) => panic!(),
|
||||
Named(ref fields) => fields.as_slice(),
|
||||
Named(ref fields) => &fields[],
|
||||
};
|
||||
|
||||
// Convert each field into a unique ident.
|
||||
|
@ -295,8 +295,8 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
Token::Str(value) if value.chars().count() == 1 => {
|
||||
Ok(value.char_at(0))
|
||||
}
|
||||
Token::String(ref value) if value.as_slice().chars().count() == 1 => {
|
||||
Ok(value.as_slice().char_at(0))
|
||||
Token::String(ref value) if value[].chars().count() == 1 => {
|
||||
Ok(value[].char_at(0))
|
||||
}
|
||||
token => {
|
||||
static EXPECTED_TOKENS: &'static [TokenKind] = &[
|
||||
@ -410,7 +410,7 @@ pub trait Deserializer<E>: Iterator<Item=Result<Token, E>> + Sized {
|
||||
Ok(Some(fields.iter().position(|field| *field == n)))
|
||||
}
|
||||
Token::String(n) => {
|
||||
Ok(Some(fields.iter().position(|field| *field == n.as_slice())))
|
||||
Ok(Some(fields.iter().position(|field| *field == &n[])))
|
||||
}
|
||||
token => {
|
||||
Err(self.syntax_error(token, STR_TOKEN_KINDS))
|
||||
|
@ -399,7 +399,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
|
||||
|
||||
let buf = &mut [0u8; 4];
|
||||
let len = c.encode_utf8(buf).unwrap_or(0);
|
||||
self.buf.extend(buf.slice_to(len).iter().map(|b| *b));
|
||||
self.buf.extend(buf[..len].iter().map(|b| *b));
|
||||
}
|
||||
_ => {
|
||||
return Err(self.error(ErrorCode::InvalidEscape));
|
||||
@ -580,7 +580,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
|
||||
_ => { return Err(self.error(ErrorCode::ExpectedEnumToken)); }
|
||||
}
|
||||
|
||||
match variants.iter().position(|v| *v == variant.as_slice()) {
|
||||
match variants.iter().position(|v| *v == &variant[]) {
|
||||
Some(idx) => Ok(idx),
|
||||
None => Err(self.error(ErrorCode::UnknownVariant)),
|
||||
}
|
||||
@ -631,7 +631,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
|
||||
None => { return Ok(None); }
|
||||
};
|
||||
|
||||
Ok(Some(fields.iter().position(|field| *field == s.as_slice())))
|
||||
Ok(Some(fields.iter().position(|field| *field == &s[])))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> IoResult<()> {
|
||||
};
|
||||
|
||||
if start < i {
|
||||
try!(wr.write(bytes.slice(start, i)));
|
||||
try!(wr.write(&bytes[start..i]));
|
||||
}
|
||||
|
||||
try!(wr.write_str(escaped));
|
||||
@ -34,7 +34,7 @@ fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> IoResult<()> {
|
||||
}
|
||||
|
||||
if start != bytes.len() {
|
||||
try!(wr.write(bytes.slice_from(start)));
|
||||
try!(wr.write(&bytes[start..]));
|
||||
}
|
||||
|
||||
wr.write_str("\"")
|
||||
@ -74,7 +74,7 @@ fn spaces<W: Writer>(wr: &mut W, mut n: usize) -> IoResult<()> {
|
||||
}
|
||||
|
||||
if n > 0 {
|
||||
wr.write(BUF.slice_to(n))
|
||||
wr.write(&BUF[..n])
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ impl de::Deserializer<Error> for Deserializer {
|
||||
}
|
||||
};
|
||||
|
||||
match variants.iter().position(|v| *v == variant.as_slice()) {
|
||||
match variants.iter().position(|v| *v == &variant[]) {
|
||||
Some(idx) => Ok(idx),
|
||||
None => Err(Error::UnknownVariantError(variant)),
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ impl<'a, S: Serializer<E>, E> Serialize<S, E> for &'a str {
|
||||
impl<S: Serializer<E>, E> Serialize<S, E> for String {
|
||||
#[inline]
|
||||
fn serialize(&self, s: &mut S) -> Result<(), E> {
|
||||
self.as_slice().serialize(s)
|
||||
(&self[]).serialize(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ fn test_json_struct() {
|
||||
};
|
||||
|
||||
let s = serde::json::to_string(&input).unwrap();
|
||||
assert_eq!(s.as_slice(), r#"{"$schema":"a","title":"b","type":3}"#);
|
||||
assert_eq!(&s[], r#"{"$schema":"a","title":"b","type":3}"#);
|
||||
|
||||
let output: Test = serde::json::from_str(&s).unwrap();
|
||||
assert_eq!(input, output);
|
||||
|
Loading…
Reference in New Issue
Block a user