Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5431727b
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5431727b
编写于
1月 18, 2015
作者:
A
Alfie John
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: replacing more deprecated integer suffixes
上级
66003c06
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
80 deletion
+80
-80
src/doc/reference.md
src/doc/reference.md
+80
-80
未找到文件。
src/doc/reference.md
浏览文件 @
5431727b
...
...
@@ -578,8 +578,8 @@ Two examples of paths with type arguments:
# struct HashMap<K, V>;
# fn f() {
# fn id<T>(t: T) -> T { t }
type T = HashMap<i
nt,String>;
// Type arguments used in a type expression
let x
= id::<int
>(10); // Type arguments used in a call expression
type T = HashMap<i
32,String>;
// Type arguments used in a type expression
let x
= id::<i32
>(10); // Type arguments used in a call expression
# }
```
...
...
@@ -1104,7 +1104,7 @@ interpreted as an implicit `return` expression applied to the final-expression.
An example of a function:
```
fn add(x: i
nt, y: int) -> int
{
fn add(x: i
32, y: i32) -> i32
{
return x + y;
}
```
...
...
@@ -1113,7 +1113,7 @@ As with `let` bindings, function arguments are irrefutable patterns, so any
pattern that is valid in a let binding is also valid as an argument.
```
fn first((value, _): (i
nt, int)) -> int
{ value }
fn first((value, _): (i
32, i32)) -> i32
{ value }
```
...
...
@@ -1139,8 +1139,8 @@ used as a type name.
When a generic function is referenced, its type is instantiated based on the
context of the reference. For example, calling the
`iter`
function defined
above on
`[1, 2]`
will instantiate type parameter
`T`
with
`i
nt
`
, and require
the closure parameter to have type
`fn(i
nt
)`
.
above on
`[1, 2]`
will instantiate type parameter
`T`
with
`i
size
`
, and require
the closure parameter to have type
`fn(i
size
)`
.
The type parameters can also be explicitly supplied in a trailing
[
path
](
#paths
)
component after the function name. This might be necessary if
...
...
@@ -1272,7 +1272,7 @@ typecheck:
```
# fn my_err(s: &str) -> ! { panic!() }
fn f(i: i
nt) -> int
{
fn f(i: i
32) -> i32
{
if i == 42 {
return 42;
}
...
...
@@ -1283,7 +1283,7 @@ fn f(i: int) -> int {
```
This will not compile without the
`!`
annotation on
`my_err`
, since the
`else`
branch of the conditional in
`f`
does not return an
`i
nt
`
, as required by the
branch of the conditional in
`f`
does not return an
`i
32
`
, as required by the
signature of
`f`
. Adding the
`!`
annotation to
`my_err`
informs the
typechecker that, should control ever enter
`my_err`
, no further type judgments
about
`f`
need to hold, since control will never resume in any context that
...
...
@@ -1301,18 +1301,18 @@ modifier.
```
// Declares an extern fn, the ABI defaults to "C"
extern fn new_i
nt() -> int
{ 0 }
extern fn new_i
32() -> i32
{ 0 }
// Declares an extern fn with "stdcall" ABI
extern "stdcall" fn new_i
nt_stdcall() -> int
{ 0 }
extern "stdcall" fn new_i
32_stdcall() -> i32
{ 0 }
```
Unlike normal functions, extern fns have an
`extern "ABI" fn()`
. This is the
same type as the functions declared in an extern block.
```
# extern fn new_i
nt() -> int
{ 0 }
let fptr: extern "C" fn() -> i
nt = new_int
;
# extern fn new_i
32() -> i32
{ 0 }
let fptr: extern "C" fn() -> i
32 = new_i32
;
```
Extern functions may be called directly from Rust code as Rust uses large,
...
...
@@ -1348,18 +1348,18 @@ keyword `struct`.
An example of a
`struct`
item and its use:
```
struct Point {x: i
nt, y: int
}
struct Point {x: i
32, y: i32
}
let p = Point {x: 10, y: 11};
let px: i
nt
= p.x;
let px: i
32
= p.x;
```
A _tuple structure_ is a nominal
[
tuple type
](
#tuple-types
)
, also defined with
the keyword
`struct`
. For example:
```
struct Point(i
nt, int
);
struct Point(i
32, i32
);
let p = Point(10, 11);
let px: i
nt
= match p { Point(x, _) => x };
let px: i
32
= match p { Point(x, _) => x };
```
A _unit-like struct_ is a structure without any fields, defined by leaving off
...
...
@@ -1457,14 +1457,14 @@ a type derived from those primitive types. The derived types are references with
the
`static`
lifetime, fixed-size arrays, tuples, enum variants, and structs.
```
const BIT1: u
int
= 1 << 0;
const BIT2: u
int
= 1 << 1;
const BIT1: u
32
= 1 << 0;
const BIT2: u
32
= 1 << 1;
const BITS: [u
int
; 2] = [BIT1, BIT2];
const BITS: [u
32
; 2] = [BIT1, BIT2];
const STRING: &'static str = "bitstring";
struct BitsNStrings<'a> {
mybits: [u
int
; 2],
mybits: [u
32
; 2],
mystring: &'a str
}
...
...
@@ -1500,14 +1500,14 @@ Constants should in general be preferred over statics, unless large amounts of
data are being stored, or single-address and mutability properties are required.
```
use std::sync::atomic::{AtomicUint, Ordering, ATOMIC_U
INT
_INIT};;
use std::sync::atomic::{AtomicUint, Ordering, ATOMIC_U
SIZE
_INIT};;
// Note that ATOMIC_U
INT
_INIT is a *const*, but it may be used to initialize a
// Note that ATOMIC_U
SIZE
_INIT is a *const*, but it may be used to initialize a
// static. This static can be modified, so it is not placed in read-only memory.
static COUNTER: AtomicUint = ATOMIC_U
INT
_INIT;
static COUNTER: AtomicUint = ATOMIC_U
SIZE
_INIT;
// This table is a candidate to be placed in read-only memory.
static TABLE: &'static [u
int
] = &[1, 2, 3, /* ... */];
static TABLE: &'static [u
size
] = &[1, 2, 3, /* ... */];
for slot in TABLE.iter() {
println!("{}", slot);
...
...
@@ -1529,13 +1529,13 @@ Mutable statics are still very useful, however. They can be used with C
libraries and can also be bound from C libraries (in an
`extern`
block).
```
# fn atomic_add(_: &mut u
int, _: uint) -> uint
{ 2 }
# fn atomic_add(_: &mut u
32, _: u32) -> u32
{ 2 }
static mut LEVELS: u
int
= 0;
static mut LEVELS: u
32
= 0;
// This violates the idea of no shared state, and this doesn't internally
// protect against races, so this function is `unsafe`
unsafe fn bump_levels_unsafe1() -> u
int
{
unsafe fn bump_levels_unsafe1() -> u
32
{
let ret = LEVELS;
LEVELS += 1;
return ret;
...
...
@@ -1544,7 +1544,7 @@ unsafe fn bump_levels_unsafe1() -> uint {
// Assuming that we have an atomic_add function which returns the old value,
// this function is "safe" but the meaning of the return value may not be what
// callers expect, so it's still marked as `unsafe`
unsafe fn bump_levels_unsafe2() -> u
int
{
unsafe fn bump_levels_unsafe2() -> u
32
{
return atomic_add(&mut LEVELS, 1);
}
```
...
...
@@ -1564,8 +1564,8 @@ Traits are implemented for specific types through separate
[
implementations
](
#implementations
)
.
```
# type Surface = i
nt
;
# type BoundingBox = i
nt
;
# type Surface = i
32
;
# type BoundingBox = i
32
;
trait Shape {
fn draw(&self, Surface);
fn bounding_box(&self) -> BoundingBox;
...
...
@@ -1583,8 +1583,8 @@ functions](#generic-functions).
```
trait Seq<T> {
fn len(&self) -> u
int
;
fn elt_at(&self, n: u
int
) -> T;
fn len(&self) -> u
32
;
fn elt_at(&self, n: u
32
) -> T;
fn iter<F>(&self, F) where F: Fn(T);
}
```
...
...
@@ -1595,7 +1595,7 @@ parameter, and within the generic function, the methods of the trait can be
called on values that have the parameter's type. For example:
```
# type Surface = i
nt
;
# type Surface = i
32
;
# trait Shape { fn draw(&self, Surface); }
fn draw_twice<T: Shape>(surface: Surface, sh: T) {
sh.draw(surface);
...
...
@@ -1610,8 +1610,8 @@ trait is in scope) to pointers to the trait name, used as a type.
```
# trait Shape { }
# impl Shape for i
nt
{ }
# let mycircle = 0i
s
;
# impl Shape for i
32
{ }
# let mycircle = 0i
32
;
let myshape: Box<Shape> = Box::new(mycircle) as Box<Shape>;
```
...
...
@@ -1629,12 +1629,12 @@ module. For example:
```
trait Num {
fn from_i
nt(n: int
) -> Self;
fn from_i
32(n: i32
) -> Self;
}
impl Num for f64 {
fn from_i
nt(n: int
) -> f64 { n as f64 }
fn from_i
32(n: i32
) -> f64 { n as f64 }
}
let x: f64 = Num::from_i
nt
(42);
let x: f64 = Num::from_i
32
(42);
```
Traits may inherit from other traits. For example, in
...
...
@@ -1669,9 +1669,9 @@ Likewise, supertrait methods may also be called on trait objects.
```
{.ignore}
# trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> f64; }
# impl Shape for i
nt
{ fn area(&self) -> f64 { 0.0 } }
# impl Circle for i
nt
{ fn radius(&self) -> f64 { 0.0 } }
# let mycircle = 0;
# impl Shape for i
32
{ fn area(&self) -> f64 { 0.0 } }
# impl Circle for i
32
{ fn radius(&self) -> f64 { 0.0 } }
# let mycircle = 0
i32
;
let mycircle = Box::new(mycircle) as Box<Circle>;
let nonsense = mycircle.radius() * mycircle.area();
```
...
...
@@ -1686,7 +1686,7 @@ Implementations are defined with the keyword `impl`.
```
# struct Point {x: f64, y: f64};
# impl Copy for Point {}
# type Surface = i
nt
;
# type Surface = i
32
;
# struct BoundingBox {x: f64, y: f64, width: f64, height: f64};
# trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; }
# fn do_draw_circle(s: Surface, c: Circle) { }
...
...
@@ -1715,7 +1715,7 @@ limited to nominal types (enums, structs), and the implementation must appear
in the same module or a sub-module as the
`self`
type:
```
struct Point {x: i
nt, y: int
}
struct Point {x: i
32, y: i32
}
impl Point {
fn log(&self) {
...
...
@@ -1826,7 +1826,7 @@ struct Foo;
// Declare a public struct with a private field
pub struct Bar {
field: i
nt
field: i
32
}
// Declare a public enum with two public variants
...
...
@@ -2226,15 +2226,15 @@ plugins](book/plugin.html#lint-plugins) can provide additional lint checks.
mod m1 {
// Missing documentation is ignored here
#[allow(missing_docs)]
pub fn undocumented_one() -> i
nt
{ 1 }
pub fn undocumented_one() -> i
32
{ 1 }
// Missing documentation signals a warning here
#[warn(missing_docs)]
pub fn undocumented_too() -> i
nt
{ 2 }
pub fn undocumented_too() -> i
32
{ 2 }
// Missing documentation signals an error here
#[deny(missing_docs)]
pub fn undocumented_end() -> i
nt
{ 3 }
pub fn undocumented_end() -> i
32
{ 3 }
}
```
...
...
@@ -2247,16 +2247,16 @@ mod m2{
#[allow(missing_docs)]
mod nested {
// Missing documentation is ignored here
pub fn undocumented_one() -> i
nt
{ 1 }
pub fn undocumented_one() -> i
32
{ 1 }
// Missing documentation signals a warning here,
// despite the allow above.
#[warn(missing_docs)]
pub fn undocumented_two() -> i
nt
{ 2 }
pub fn undocumented_two() -> i
32
{ 2 }
}
// Missing documentation signals a warning here
pub fn undocumented_too() -> i
nt
{ 3 }
pub fn undocumented_too() -> i
32
{ 3 }
}
```
...
...
@@ -2269,7 +2269,7 @@ mod m3 {
// Attempting to toggle warning signals an error here
#[allow(missing_docs)]
/// Returns 2.
pub fn undocumented_too() -> i
nt
{ 2 }
pub fn undocumented_too() -> i
32
{ 2 }
}
```
...
...
@@ -2461,7 +2461,7 @@ the `PartialEq` or `Clone` constraints for the appropriate `impl`:
```
#[derive(PartialEq, Clone)]
struct Foo<T> {
a: i
nt
,
a: i
32
,
b: T
}
```
...
...
@@ -2469,7 +2469,7 @@ struct Foo<T> {
The generated
`impl`
for
`PartialEq`
is equivalent to
```
# struct Foo<T> { a: i
nt
, b: T }
# struct Foo<T> { a: i
32
, b: T }
impl<T: PartialEq> PartialEq for Foo<T> {
fn eq(&self, other: &Foo<T>) -> bool {
self.a == other.a && self.b == other.b
...
...
@@ -2862,7 +2862,7 @@ The following are examples of structure expressions:
```
# struct Point { x: f64, y: f64 }
# struct TuplePoint(f64, f64);
# mod game { pub struct User<'a> { pub name: &'a str, pub age: u
int
, pub score: uint } }
# mod game { pub struct User<'a> { pub name: &'a str, pub age: u
32
, pub score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10.0, y: 20.0};
TuplePoint(10.0, 20.0);
...
...
@@ -2883,7 +2883,7 @@ were explicitly specified and the values in the base expression for all other
fields.
```
# struct Point3d { x: i
nt, y: int, z: int
}
# struct Point3d { x: i
32, y: i32, z: i32
}
let base = Point3d {x: 1, y: 2, z: 3};
Point3d {y: 0, z: 10, .. base};
```
...
...
@@ -3113,7 +3113,7 @@ An example of an `as` expression:
```
# fn sum(v: &[f64]) -> f64 { 0.0 }
# fn len(v: &[f64]) -> i
nt
{ 0 }
# fn len(v: &[f64]) -> i
32
{ 0 }
fn avg(v: &[f64]) -> f64 {
let sum: f64 = sum(v);
...
...
@@ -3184,7 +3184,7 @@ paren_expr : '(' expr ')' ;
An example of a parenthesized expression:
```
let x: i
nt
= (2 + 3) * 4;
let x: i
32
= (2 + 3) * 4;
```
...
...
@@ -3204,9 +3204,9 @@ then the expression completes.
Some examples of call expressions:
```
# fn add(x: i
nt, y: int) -> int
{ 0 }
# fn add(x: i
32, y: i32) -> i32
{ 0 }
let x: i
nt = add(1,
2);
let x: i
32 = add(1i32, 2i3
2);
let pi: Option<f32> = "3.14".parse();
```
...
...
@@ -3245,8 +3245,8 @@ In this example, we define a function `ten_times` that takes a higher-order
function argument, and call it with a lambda expression as an argument:
```
fn ten_times<F>(f: F) where F: Fn(i
nt
) {
let mut i = 0;
fn ten_times<F>(f: F) where F: Fn(i
32
) {
let mut i = 0
i32
;
while i < 10 {
f(i);
i += 1;
...
...
@@ -3333,7 +3333,7 @@ by an implementation of `std::iter::Iterator`.
An example of a for loop over the contents of an array:
```
# type Foo = i
nt
;
# type Foo = i
32
;
# fn bar(f: Foo) { }
# let a = 0;
# let b = 0;
...
...
@@ -3402,7 +3402,7 @@ fields of a particular variant. For example:
enum List<X> { Nil, Cons(X, Box<List<X>>) }
fn main() {
let x: List<i
nt
> = List::Cons(10, box List::Cons(11, box List::Nil));
let x: List<i
32
> = List::Cons(10, box List::Cons(11, box List::Nil));
match x {
List::Cons(_, box List::Nil) => panic!("singleton list"),
...
...
@@ -3428,7 +3428,7 @@ corresponding slice to the variable. Example:
```
# #![feature(advanced_slice_patterns)]
fn is_symmetric(list: &[u
int
]) -> bool {
fn is_symmetric(list: &[u
32
]) -> bool {
match list {
[] | [_] => true,
[x, inside.., y] if x == y => is_symmetric(inside),
...
...
@@ -3437,8 +3437,8 @@ fn is_symmetric(list: &[uint]) -> bool {
}
fn main() {
let sym = &[0, 1, 4, 2, 4, 1, 0];
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
let sym = &[0
us
, 1, 4, 2, 4, 1, 0];
let not_sym = &[0
us
, 1, 7, 2, 4, 1, 0];
assert!(is_symmetric(sym));
assert!(!is_symmetric(not_sym));
}
...
...
@@ -3462,13 +3462,13 @@ An example of a `match` expression:
```
#![feature(box_syntax)]
# fn process_pair(a: i
nt, b: int
) { }
# fn process_pair(a: i
32, b: i32
) { }
# fn process_ten() { }
enum List<X> { Nil, Cons(X, Box<List<X>>) }
fn main() {
let x: List<i
nt
> = List::Cons(10, box List::Cons(11, box List::Nil));
let x: List<i
32
> = List::Cons(10, box List::Cons(11, box List::Nil));
match x {
List::Cons(a, box List::Cons(b, _)) => {
...
...
@@ -3565,8 +3565,8 @@ may refer to the variables bound within the pattern they follow.
```
# let maybe_digit = Some(0);
# fn process_digit(i: i
nt
) { }
# fn process_other(i: i
nt
) { }
# fn process_digit(i: i
32
) { }
# fn process_other(i: i
32
) { }
let message = match maybe_digit {
Some(x) if x < 10 => process_digit(x),
...
...
@@ -3614,7 +3614,7 @@ caller frame.
An example of a
`return`
expression:
```
fn max(a: i
nt, b: int) -> int
{
fn max(a: i
32, b: i32) -> i32
{
if a > b {
return a;
}
...
...
@@ -3666,12 +3666,12 @@ The machine types are the following:
#### Machine-dependent integer types
The
`u
int
`
type is an unsigned integer type with the same number of bits as the
The
`u
size
`
type is an unsigned integer type with the same number of bits as the
platform's pointer type. It can represent every memory address in the process.
The
`i
nt
`
type is a signed integer type with the same number of bits as the
The
`i
size
`
type is a signed integer type with the same number of bits as the
platform's pointer type. The theoretical upper bound on object and array size
is the maximum
`i
nt`
value. This ensures that
`int
`
can be used to calculate
is the maximum
`i
size`
value. This ensures that
`isize
`
can be used to calculate
differences between pointers into an object or array and can address every byte
within an object along with one byte past the end.
...
...
@@ -3707,7 +3707,7 @@ by the tuple type.
An example of a tuple type and its use:
```
type Pair<'a> = (i
nt
, &'a str);
type Pair<'a> = (i
32
, &'a str);
let p: Pair<'static> = (10, "hello");
let (a, b) = p;
assert!(b != "world");
...
...
@@ -3858,13 +3858,13 @@ or `extern`), a sequence of input types and an output type.
An example of a
`fn`
type:
```
fn add(x: i
nt, y: int) -> int
{
fn add(x: i
32, y: i32) -> i32
{
return x + y;
}
let mut x = add(5,7);
type Binop = fn(i
nt, int) -> int
;
type Binop = fn(i
32, i32) -> i32
;
let bo: Binop = add;
x = bo(5,7);
```
...
...
@@ -4102,7 +4102,7 @@ Local variables are immutable unless declared otherwise like: `let mut x = ...`.
Function parameters are immutable unless declared with
`mut`
. The
`mut`
keyword
applies only to the following parameter (so
`|mut x, y|`
and
`fn f(mut x:
Box<i
nt>, y: Box<int
>)`
declare one mutable variable
`x`
and one immutable
Box<i
32>, y: Box<i32
>)`
declare one mutable variable
`x`
and one immutable
variable
`y`
).
Methods that take either
`self`
or
`Box<Self>`
can optionally place them in a
...
...
@@ -4130,7 +4130,7 @@ the type of a box is `std::owned::Box<T>`.
An example of a box type and value:
```
let x: Box<i
nt
> = Box::new(10);
let x: Box<i
32
> = Box::new(10);
```
Box values exist in 1:1 correspondence with their heap allocation, copying a
...
...
@@ -4139,7 +4139,7 @@ copy of a box to move ownership of the value. After a value has been moved,
the source location cannot be used unless it is reinitialized.
```
let x: Box<i
nt
> = Box::new(10);
let x: Box<i
32
> = Box::new(10);
let y = x;
// attempting to use `x` will result in an error here
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录