Follow rust std: int, uint were renamed to isize, usize

This commit is contained in:
Thomas Bahn
2015-02-06 14:14:35 +01:00
parent 3b5d71fbb5
commit 361acd37d0
15 changed files with 443 additions and 443 deletions
+8 -8
View File
@@ -93,22 +93,22 @@ mod tests {
assert_eq!(value, Value::Array(Vec::new()));
let value = ArrayBuilder::new()
.push(1i)
.push(2i)
.push(3i)
.push(1is)
.push(2is)
.push(3is)
.unwrap();
assert_eq!(value, Value::Array(vec!(Value::Integer(1), Value::Integer(2), Value::Integer(3))));
let value = ArrayBuilder::new()
.push_array(|bld| bld.push(1i).push(2i).push(3i))
.push_array(|bld| bld.push(1is).push(2is).push(3is))
.unwrap();
assert_eq!(value, Value::Array(vec!(Value::Array(vec!(Value::Integer(1), Value::Integer(2), Value::Integer(3))))));
let value = ArrayBuilder::new()
.push_object(|bld|
bld
.insert("a".to_string(), 1i)
.insert("b".to_string(), 2i))
.insert("a".to_string(), 1is)
.insert("b".to_string(), 2is))
.unwrap();
let mut map = BTreeMap::new();
@@ -123,8 +123,8 @@ mod tests {
assert_eq!(value, Value::Object(BTreeMap::new()));
let value = ObjectBuilder::new()
.insert("a".to_string(), 1i)
.insert("b".to_string(), 2i)
.insert("a".to_string(), 1is)
.insert("b".to_string(), 2is)
.unwrap();
let mut map = BTreeMap::new();
+11 -11
View File
@@ -30,8 +30,8 @@ enum State {
pub struct Parser<Iter> {
rdr: Iter,
ch: Option<u8>,
line: uint,
col: uint,
line: usize,
col: usize,
// A state machine is kept to make it possible to interupt and resume parsing.
state_stack: Vec<State>,
buf: Vec<u8>,
@@ -261,7 +261,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
match self.ch_or_null() {
c @ b'0' ... b'9' => {
dec /= 10.0;
res += (((c as int) - (b'0' as int)) as f64) * dec;
res += (((c as isize) - (b'0' as isize)) as f64) * dec;
self.bump();
}
_ => break,
@@ -275,7 +275,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
fn parse_exponent(&mut self, mut res: f64) -> Result<f64, Error> {
self.bump();
let mut exp = 0u;
let mut exp = 0us;
let mut neg_exp = false;
if self.ch_is(b'+') {
@@ -294,7 +294,7 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
match self.ch_or_null() {
c @ b'0' ... b'9' => {
exp *= 10;
exp += (c as uint) - (b'0' as uint);
exp += (c as usize) - (b'0' as usize);
self.bump();
}
@@ -314,9 +314,9 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
#[inline]
fn decode_hex_escape(&mut self) -> Result<u16, Error> {
let mut i = 0u;
let mut i = 0us;
let mut n = 0u16;
while i < 4u && !self.eof() {
while i < 4us && !self.eof() {
self.bump();
n = match self.ch_or_null() {
c @ b'0' ... b'9' => n * 16_u16 + ((c as u16) - (b'0' as u16)),
@@ -329,11 +329,11 @@ impl<Iter: Iterator<Item=u8>> Parser<Iter> {
_ => { return Err(self.error(ErrorCode::InvalidEscape)); }
};
i += 1u;
i += 1us;
}
// Error out if we didn't parse 4 digits.
if i != 4u {
if i != 4us {
return Err(self.error(ErrorCode::InvalidEscape));
}
@@ -562,7 +562,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
fn expect_enum_start(&mut self,
token: de::Token,
_name: &str,
variants: &[&str]) -> Result<uint, Error> {
variants: &[&str]) -> Result<usize, Error> {
match token {
de::Token::MapStart(_) => { }
_ => { return Err(self.error(ErrorCode::ExpectedEnumMapStart)); }
@@ -615,7 +615,7 @@ impl<Iter: Iterator<Item=u8>> de::Deserializer<Error> for Parser<Iter> {
#[inline]
fn expect_struct_field_or_end(&mut self,
fields: &'static [&'static str]
) -> Result<Option<Option<uint>>, Error> {
) -> Result<Option<Option<usize>>, Error> {
let result = match self.state_stack.pop() {
Some(State::ObjectStart) => {
try!(self.parse_object_start())
+1 -1
View File
@@ -81,7 +81,7 @@ impl fmt::Show for ErrorCode {
#[derive(Clone, PartialEq, Show)]
pub enum Error {
/// msg, line, col
SyntaxError(ErrorCode, uint, uint),
SyntaxError(ErrorCode, usize, usize),
IoError(io::IoError),
ExpectedError(String, String),
MissingFieldError(String),
+41 -41
View File
@@ -362,7 +362,7 @@ mod tests {
#[derive_deserialize]
enum Animal {
Dog,
Frog(String, Vec<int>)
Frog(String, Vec<isize>)
}
impl ToJson for Animal {
@@ -391,7 +391,7 @@ mod tests {
#[derive_deserialize]
struct Inner {
a: (),
b: uint,
b: usize,
c: Vec<string::String>,
}
@@ -464,9 +464,9 @@ mod tests {
#[test]
fn test_write_i64() {
let tests = &[
(3i, "3"),
(-2i, "-2"),
(-1234i, "-1234"),
(3is, "3"),
(-2is, "-2"),
(-1234is, "-1234"),
];
test_encode_ok(tests);
test_pretty_encode_ok(tests);
@@ -643,14 +643,14 @@ mod tests {
fn test_write_tuple() {
test_encode_ok(&[
(
(5i,),
(5is,),
"[5]",
),
]);
test_pretty_encode_ok(&[
(
(5i,),
(5is,),
concat!(
"[\n",
" 5\n",
@@ -661,14 +661,14 @@ mod tests {
test_encode_ok(&[
(
(5i, (6i, "abc")),
(5is, (6is, "abc")),
"[5,[6,\"abc\"]]",
),
]);
test_pretty_encode_ok(&[
(
(5i, (6i, "abc")),
(5is, (6is, "abc")),
concat!(
"[\n",
" 5,\n",
@@ -964,19 +964,19 @@ mod tests {
]);
test_parse_ok(&[
("[3,1]", vec!(3i, 1)),
("[ 3 , 1 ]", vec!(3i, 1)),
("[3,1]", vec!(3is, 1)),
("[ 3 , 1 ]", vec!(3is, 1)),
]);
test_parse_ok(&[
("[[3], [1, 2]]", vec!(vec!(3i), vec!(1, 2))),
("[[3], [1, 2]]", vec!(vec!(3is), vec!(1, 2))),
]);
let v: () = from_str("[]").unwrap();
assert_eq!(v, ());
test_parse_ok(&[
("[1, 2, 3]", (1u, 2u, 3u)),
("[1, 2, 3]", (1us, 2us, 3us)),
]);
}
@@ -992,17 +992,17 @@ mod tests {
]);
test_json_deserialize_ok(&[
vec!(3i, 1),
vec!(3is, 1),
]);
test_json_deserialize_ok(&[
vec!(vec!(3i), vec!(1, 2)),
vec!(vec!(3is), vec!(1, 2)),
]);
}
#[test]
fn test_parse_object() {
test_parse_err::<BTreeMap<string::String, int>>(&[
test_parse_err::<BTreeMap<string::String, isize>>(&[
("{", SyntaxError(EOFWhileParsingString, 1, 2)),
("{ ", SyntaxError(EOFWhileParsingString, 1, 3)),
("{1", SyntaxError(KeyMustBeAString, 1, 2)),
@@ -1022,26 +1022,26 @@ mod tests {
("{ }", treemap!()),
(
"{\"a\":3}",
treemap!("a".to_string() => 3i)
treemap!("a".to_string() => 3is)
),
(
"{ \"a\" : 3 }",
treemap!("a".to_string() => 3i)
treemap!("a".to_string() => 3is)
),
(
"{\"a\":3,\"b\":4}",
treemap!("a".to_string() => 3i, "b".to_string() => 4)
treemap!("a".to_string() => 3is, "b".to_string() => 4)
),
(
"{ \"a\" : 3 , \"b\" : 4 }",
treemap!("a".to_string() => 3i, "b".to_string() => 4),
treemap!("a".to_string() => 3is, "b".to_string() => 4),
),
]);
test_parse_ok(&[
(
"{\"a\": {\"b\": 3, \"c\": 4}}",
treemap!("a".to_string() => treemap!("b".to_string() => 3i, "c".to_string() => 4i)),
treemap!("a".to_string() => treemap!("b".to_string() => 3is, "c".to_string() => 4is)),
),
]);
}
@@ -1050,12 +1050,12 @@ mod tests {
fn test_json_deserialize_object() {
test_json_deserialize_ok(&[
treemap!(),
treemap!("a".to_string() => 3i),
treemap!("a".to_string() => 3i, "b".to_string() => 4),
treemap!("a".to_string() => 3is),
treemap!("a".to_string() => 3is, "b".to_string() => 4),
]);
test_json_deserialize_ok(&[
treemap!("a".to_string() => treemap!("b".to_string() => 3i, "c".to_string() => 4)),
treemap!("a".to_string() => treemap!("b".to_string() => 3is, "c".to_string() => 4)),
]);
}
@@ -1107,7 +1107,7 @@ mod tests {
#[derive_serialize]
#[derive_deserialize]
struct Foo {
x: Option<int>,
x: Option<isize>,
}
let value: Foo = from_str("{}").unwrap();
@@ -1172,7 +1172,7 @@ mod tests {
#[test]
fn test_multiline_errors() {
test_parse_err::<BTreeMap<string::String, string::String>>(&[
("{\n \"foo\":\n \"bar\"", SyntaxError(EOFWhileParsingObject, 3u, 8u)),
("{\n \"foo\":\n \"bar\"", SyntaxError(EOFWhileParsingObject, 3us, 8us)),
]);
}
@@ -1371,7 +1371,7 @@ mod tests {
fn test_encode_hashmap_with_numeric_key() {
use std::str::from_utf8;
use std::collections::HashMap;
let mut hm: HashMap<uint, bool> = HashMap::new();
let mut hm: HashMap<usize, bool> = HashMap::new();
hm.insert(1, true);
let mut mem_buf = MemWriter::new();
{
@@ -1386,7 +1386,7 @@ mod tests {
fn test_prettyencode_hashmap_with_numeric_key() {
use std::str::from_utf8;
use std::collections::HashMap;
let mut hm: HashMap<uint, bool> = HashMap::new();
let mut hm: HashMap<usize, bool> = HashMap::new();
hm.insert(1, true);
let mut mem_buf = MemWriter::new();
{
@@ -1402,7 +1402,7 @@ mod tests {
fn test_hashmap_with_numeric_key_can_handle_double_quote_delimited_key() {
use std::collections::HashMap;
let json_str = "{\"1\":true}";
let map: HashMap<uint, bool> = from_str(json_str).unwrap();
let map: HashMap<usize, bool> = from_str(json_str).unwrap();
let mut m = HashMap::new();
m.insert(1u, true);
assert_eq!(map, m);
@@ -1715,7 +1715,7 @@ mod bench {
})
}
fn json_str(count: uint) -> string::String {
fn json_str(count: usize) -> string::String {
let mut src = "[".to_string();
for _ in range(0, count) {
src.push_str(r#"{"a":true,"b":null,"c":3.1415,"d":"Hello world","e":[1,2,3]},"#);
@@ -1724,7 +1724,7 @@ mod bench {
src
}
fn pretty_json_str(count: uint) -> string::String {
fn pretty_json_str(count: usize) -> string::String {
let mut src = "[\n".to_string();
for _ in range(0, count) {
src.push_str(
@@ -1747,7 +1747,7 @@ mod bench {
src
}
fn encoder_json(count: uint) -> serialize::json::Json {
fn encoder_json(count: usize) -> serialize::json::Json {
use serialize::json::Json;
let mut list = vec!();
@@ -1768,7 +1768,7 @@ mod bench {
Json::Array(list)
}
fn serializer_json(count: uint) -> Value {
fn serializer_json(count: usize) -> Value {
let mut list = vec!();
for _ in range(0, count) {
list.push(Value::Object(treemap!(
@@ -1787,7 +1787,7 @@ mod bench {
Value::Array(list)
}
fn bench_encoder(b: &mut Bencher, count: uint) {
fn bench_encoder(b: &mut Bencher, count: usize) {
let src = json_str(count);
let json = encoder_json(count);
@@ -1796,7 +1796,7 @@ mod bench {
});
}
fn bench_encoder_pretty(b: &mut Bencher, count: uint) {
fn bench_encoder_pretty(b: &mut Bencher, count: usize) {
let src = pretty_json_str(count);
let json = encoder_json(count);
@@ -1805,7 +1805,7 @@ mod bench {
});
}
fn bench_serializer(b: &mut Bencher, count: uint) {
fn bench_serializer(b: &mut Bencher, count: usize) {
let src = json_str(count);
let json = serializer_json(count);
@@ -1814,7 +1814,7 @@ mod bench {
});
}
fn bench_serializer_pretty(b: &mut Bencher, count: uint) {
fn bench_serializer_pretty(b: &mut Bencher, count: usize) {
let src = pretty_json_str(count);
let json = serializer_json(count);
@@ -1823,7 +1823,7 @@ mod bench {
});
}
fn bench_decoder(b: &mut Bencher, count: uint) {
fn bench_decoder(b: &mut Bencher, count: usize) {
let src = json_str(count);
let json = encoder_json(count);
b.iter(|| {
@@ -1831,7 +1831,7 @@ mod bench {
});
}
fn bench_deserializer(b: &mut Bencher, count: uint) {
fn bench_deserializer(b: &mut Bencher, count: usize) {
let src = json_str(count);
let json = encoder_json(count);
b.iter(|| {
@@ -1839,7 +1839,7 @@ mod bench {
});
}
fn bench_decoder_streaming(b: &mut Bencher, count: uint) {
fn bench_decoder_streaming(b: &mut Bencher, count: usize) {
let src = json_str(count);
b.iter( || {
@@ -1878,7 +1878,7 @@ mod bench {
});
}
fn bench_deserializer_streaming(b: &mut Bencher, count: uint) {
fn bench_deserializer_streaming(b: &mut Bencher, count: usize) {
let src = json_str(count);
b.iter( || {
+13 -13
View File
@@ -64,8 +64,8 @@ fn fmt_f64_or_null<W: Writer>(wr: &mut W, v: f64) -> IoResult<()> {
}
}
fn spaces<W: Writer>(wr: &mut W, mut n: uint) -> IoResult<()> {
const LEN: uint = 16;
fn spaces<W: Writer>(wr: &mut W, mut n: usize) -> IoResult<()> {
const LEN: usize = 16;
const BUF: &'static [u8; LEN] = &[b' '; LEN];
while n >= LEN {
@@ -128,7 +128,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
}
#[inline]
fn serialize_int(&mut self, v: int) -> IoResult<()> {
fn serialize_isize(&mut self, v: isize) -> IoResult<()> {
write!(&mut self.wr, "{}", v)
}
@@ -153,7 +153,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
}
#[inline]
fn serialize_uint(&mut self, v: uint) -> IoResult<()> {
fn serialize_usize(&mut self, v: usize) -> IoResult<()> {
write!(&mut self.wr, "{}", v)
}
@@ -198,7 +198,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
}
#[inline]
fn serialize_tuple_start(&mut self, _len: uint) -> IoResult<()> {
fn serialize_tuple_start(&mut self, _len: usize) -> IoResult<()> {
self.first = true;
self.wr.write_str("[")
}
@@ -221,7 +221,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
}
#[inline]
fn serialize_struct_start(&mut self, _name: &str, _len: uint) -> IoResult<()> {
fn serialize_struct_start(&mut self, _name: &str, _len: usize) -> IoResult<()> {
self.first = true;
self.wr.write_str("{")
}
@@ -246,7 +246,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
}
#[inline]
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: uint) -> IoResult<()> {
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: usize) -> IoResult<()> {
self.first = true;
try!(self.wr.write_str("{"));
try!(self.serialize_str(variant));
@@ -329,7 +329,7 @@ impl<W: Writer> ser::Serializer<IoError> for Serializer<W> {
/// compact data
pub struct PrettySerializer<W> {
wr: W,
indent: uint,
indent: usize,
first: bool,
}
@@ -391,7 +391,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
}
#[inline]
fn serialize_int(&mut self, v: int) -> IoResult<()> {
fn serialize_isize(&mut self, v: isize) -> IoResult<()> {
write!(&mut self.wr, "{}", v)
}
@@ -416,7 +416,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
}
#[inline]
fn serialize_uint(&mut self, v: uint) -> IoResult<()> {
fn serialize_usize(&mut self, v: usize) -> IoResult<()> {
write!(&mut self.wr, "{}", v)
}
@@ -461,7 +461,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
}
#[inline]
fn serialize_tuple_start(&mut self, _len: uint) -> IoResult<()> {
fn serialize_tuple_start(&mut self, _len: usize) -> IoResult<()> {
self.first = true;
self.wr.write_str("[")
}
@@ -480,7 +480,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
}
#[inline]
fn serialize_struct_start(&mut self, _name: &str, _len: uint) -> IoResult<()> {
fn serialize_struct_start(&mut self, _name: &str, _len: usize) -> IoResult<()> {
self.first = true;
self.wr.write_str("{")
}
@@ -501,7 +501,7 @@ impl<W: Writer> ser::Serializer<IoError> for PrettySerializer<W> {
}
#[inline]
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: uint) -> IoResult<()> {
fn serialize_enum_start(&mut self, _name: &str, variant: &str, _len: usize) -> IoResult<()> {
self.first = true;
try!(self.wr.write_str("{"));
try!(self.serialize_sep());
+5 -5
View File
@@ -269,12 +269,12 @@ impl<D: de::Deserializer<E>, E> de::Deserialize<D, E> for Value {
match token {
Token::Null => Ok(Value::Null),
Token::Bool(x) => Ok(Value::Boolean(x)),
Token::Int(x) => Ok(Value::Integer(x as i64)),
Token::Isize(x) => Ok(Value::Integer(x as i64)),
Token::I8(x) => Ok(Value::Integer(x as i64)),
Token::I16(x) => Ok(Value::Integer(x as i64)),
Token::I32(x) => Ok(Value::Integer(x as i64)),
Token::I64(x) => Ok(Value::Integer(x)),
Token::Uint(x) => Ok(Value::Integer(x as i64)),
Token::Usize(x) => Ok(Value::Integer(x as i64)),
Token::U8(x) => Ok(Value::Integer(x as i64)),
Token::U16(x) => Ok(Value::Integer(x as i64)),
Token::U32(x) => Ok(Value::Integer(x as i64)),
@@ -439,7 +439,7 @@ impl de::Deserializer<Error> for Deserializer {
fn expect_enum_start(&mut self,
token: Token,
_name: &str,
variants: &[&str]) -> Result<uint, Error> {
variants: &[&str]) -> Result<usize, Error> {
let variant = match token {
Token::MapStart(_) => {
let state = match self.stack.pop() {
@@ -536,7 +536,7 @@ impl ToJson for Value {
fn to_json(&self) -> Value { (*self).clone() }
}
impl ToJson for int {
impl ToJson for isize {
fn to_json(&self) -> Value { Value::Integer(*self as i64) }
}
@@ -556,7 +556,7 @@ impl ToJson for i64 {
fn to_json(&self) -> Value { Value::Integer(*self as i64) }
}
impl ToJson for uint {
impl ToJson for usize {
fn to_json(&self) -> Value { Value::Integer(*self as i64) }
}