tutorial: Remove the entire 'Types' section
It's not interesting /cc: #4217
This commit is contained in:
parent
64681213af
commit
0b0b50aaae
@ -308,87 +308,6 @@ fn is_four(x: int) -> bool {
|
||||
}
|
||||
~~~~
|
||||
|
||||
## Types
|
||||
|
||||
The basic types include the usual boolean, integral, and floating-point types.
|
||||
|
||||
------------------------- -----------------------------------------------
|
||||
`()` Unit, the type that has only a single value
|
||||
`bool` Boolean type, with values `true` and `false`
|
||||
`int`, `uint` Machine-pointer-sized signed and unsigned integers
|
||||
`i8`, `i16`, `i32`, `i64` Signed integers with a specific size (in bits)
|
||||
`u8`, `u16`, `u32`, `u64` Unsigned integers with a specific size
|
||||
`float` The largest floating-point type efficiently supported on the target machine
|
||||
`f32`, `f64` Floating-point types with a specific size
|
||||
`char` A Unicode character (32 bits)
|
||||
------------------------- -----------------------------------------------
|
||||
|
||||
These can be combined in composite types, which will be described in
|
||||
more detail later on (the `T`s here stand for any other type,
|
||||
while N should be a literal number):
|
||||
|
||||
------------------------- -----------------------------------------------
|
||||
`[T * N]` Vector (like an array in other languages) with N elements
|
||||
`(T1, T2)` Tuple type; any arity above 1 is supported
|
||||
`&T`, `~T`, `@T` [Pointer types](#boxes-and-pointers)
|
||||
------------------------- -----------------------------------------------
|
||||
|
||||
Some types can only be manipulated by pointer, never directly. For instance,
|
||||
you cannot refer to a string (`str`); instead you refer to a pointer to a
|
||||
string (`@str`, `~str`, or `&str`). These *dynamically-sized* types consist
|
||||
of:
|
||||
|
||||
------------------------- -----------------------------------------------
|
||||
`fn(a: T1, b: T2) -> T3` Function types
|
||||
`str` String type (in UTF-8)
|
||||
`[T]` Vector with unknown size (also called a slice)
|
||||
`[mut T]` Mutable vector with unknown size
|
||||
------------------------- -----------------------------------------------
|
||||
|
||||
> ***Note***: In the future, mutability for vectors may be defined by
|
||||
> the slot that contains the vector, not the type of the vector itself,
|
||||
> deprecating [mut T] syntax.
|
||||
|
||||
In function types, the return type is specified with an arrow, as in
|
||||
the type `fn() -> bool` or the function declaration `fn foo() -> bool
|
||||
{ }`. For functions that do not return a meaningful value, you can
|
||||
optionally write `-> ()`, but usually the return annotation is simply
|
||||
left off, as in `fn main() { ... }`.
|
||||
|
||||
Types can be given names or aliases with `type` declarations:
|
||||
|
||||
~~~~
|
||||
type MonsterSize = uint;
|
||||
~~~~
|
||||
|
||||
This will provide a synonym, `MonsterSize`, for unsigned integers. It will not
|
||||
actually create a new, incompatible type—`MonsterSize` and `uint` can be used
|
||||
interchangeably, and using one where the other is expected is not a type
|
||||
error. In that sense, types declared with `type` are *structural*: their
|
||||
meaning follows from their structure, and their names are irrelevant in the
|
||||
type system.
|
||||
|
||||
Sometimes, you want your data types to be *nominal* instead of structural: you
|
||||
want their name to be part of their meaning, so that types with the same
|
||||
structure but different names are not interchangeable. Rust has two ways to
|
||||
create nominal data types: `struct` and `enum`. They're described in more
|
||||
detail below, but they look like this:
|
||||
|
||||
~~~~
|
||||
enum HidingPlaces {
|
||||
Closet(uint),
|
||||
UnderTheBed(uint)
|
||||
}
|
||||
|
||||
struct HeroicBabysitter {
|
||||
bedtime_stories: uint,
|
||||
sharpened_stakes: uint
|
||||
}
|
||||
|
||||
struct BabysitterSize(uint); // a single-variant struct
|
||||
enum MonsterSize = uint; // a single-variant enum
|
||||
~~~~
|
||||
|
||||
## Literals
|
||||
|
||||
Integers can be written in decimal (`144`), hexadecimal (`0x90`), or
|
||||
|
Loading…
Reference in New Issue
Block a user