@@ -237,7 +237,7 @@ can specify a variable's type by following it with a colon, then the type
237237name. Constants, on the other hand, always require a type annotation.
238238
239239~~~~
240- const monster_factor: float = 57.8;
240+ static monster_factor: float = 57.8;
241241let monster_size = monster_factor * 10.0;
242242let monster_size: int = 50;
243243~~~~
@@ -916,7 +916,7 @@ use core::libc::types::os::arch::c95::size_t;
916916struct Blob { priv ptr: *c_void }
917917
918918impl Blob {
919- static fn new() -> Blob {
919+ fn new() -> Blob {
920920 unsafe { Blob{ptr: calloc(1, int::bytes as size_t)} }
921921 }
922922}
@@ -1222,7 +1222,7 @@ pointers to vectors are also called 'slices'.
12221222# Black, BlizzardBlue, Blue
12231223# }
12241224// A fixed-size stack vector
1225- let stack_crayons: [ Crayon * 3] = [ Almond, AntiqueBrass, Apricot] ;
1225+ let stack_crayons: [ Crayon, .. 3] = [ Almond, AntiqueBrass, Apricot] ;
12261226
12271227// A borrowed pointer to stack-allocated vector
12281228let stack_crayons: &[ Crayon] = &[ Aquamarine, Asparagus, AtomicTangerine] ;
@@ -1264,7 +1264,7 @@ Square brackets denote indexing into a vector:
12641264# Aquamarine, Asparagus, AtomicTangerine,
12651265# BananaMania, Beaver, Bittersweet };
12661266# fn draw_scene(c: Crayon) { }
1267- let crayons: [Crayon * 3] = [BananaMania, Beaver, Bittersweet];
1267+ let crayons: [Crayon, .. 3] = [BananaMania, Beaver, Bittersweet];
12681268match crayons[0] {
12691269 Bittersweet => draw_scene(crayons[0]),
12701270 _ => ()
@@ -1274,7 +1274,7 @@ match crayons[0] {
12741274A vector can be destructured using pattern matching:
12751275
12761276~~~~
1277- let numbers: [int * 3] = [1, 2, 3];
1277+ let numbers: [int, .. 3] = [1, 2, 3];
12781278let score = match numbers {
12791279 [] => 0,
12801280 [a] => a * 10,
@@ -1768,32 +1768,25 @@ s.draw_borrowed();
17681768(&@~s).draw_borrowed();
17691769~~~
17701770
1771- Implementations may also define _ static _ methods,
1772- which don't have an explicit ` self ` argument .
1773- The ` static ` keyword distinguishes static methods from methods that have a ` self ` :
1771+ Implementations may also define standalone (sometimes called "static")
1772+ methods. The absence of a ` self ` paramater distinguishes such methods .
1773+ These methods are the preferred way to define constructor functions.
17741774
17751775~~~~ {.xfail-test}
17761776impl Circle {
17771777 fn area(&self) -> float { ... }
1778- static fn new(area: float) -> Circle { ... }
1778+ fn new(area: float) -> Circle { ... }
17791779}
17801780~~~~
17811781
1782- > *** Note*** : In the future the ` static ` keyword will be removed and static methods
1783- > will be distinguished solely by the presence or absence of the ` self ` argument.
1784- > In the current langugage instance methods may also be declared without an explicit
1785- > ` self ` argument, in which case ` self ` is an implicit reference.
1786- > That form of method is deprecated.
1787-
1788- Constructors are one common application for static methods, as in ` new ` above.
1789- To call a static method, you have to prefix it with the type name and a double colon:
1782+ To call such a method, just prefix it with the type name and a double colon:
17901783
17911784~~~~
17921785# use core::float::consts::pi;
17931786# use core::float::sqrt;
17941787struct Circle { radius: float }
17951788impl Circle {
1796- static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
1789+ fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
17971790}
17981791let c = Circle::new(42.5);
17991792~~~~
@@ -2055,22 +2048,23 @@ second parameter of type `self`.
20552048In contrast, in the ` impl ` , ` equals ` takes a second parameter of
20562049type ` int ` , only using ` self ` as the name of the receiver.
20572050
2058- Traits can also define static methods which are called by prefixing
2059- the method name with the trait name.
2060- The compiler will use type inference to decide which implementation to call.
2051+ Just as in type implementations, traits can define standalone (static)
2052+ methods. These methods are called by prefixing the method name with the trait
2053+ name and a double colon. The compiler uses type inference to decide which
2054+ implementation to use.
20612055
20622056~~~~
2063- trait Shape { static fn new(area: float) -> Self; }
2057+ trait Shape { fn new(area: float) -> Self; }
20642058# use core::float::consts::pi;
20652059# use core::float::sqrt;
20662060struct Circle { radius: float }
20672061struct Square { length: float }
20682062
20692063impl Shape for Circle {
2070- static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
2064+ fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
20712065}
20722066impl Shape for Square {
2073- static fn new(area: float) -> Square { Square { length: sqrt(area) } }
2067+ fn new(area: float) -> Square { Square { length: sqrt(area) } }
20742068}
20752069
20762070let area = 42.5;
@@ -2312,7 +2306,7 @@ them. The `pub` keyword modifies an item's visibility, making it
23122306visible outside its containing module. An expression with ` :: ` , like
23132307` farm::chicken ` , can name an item outside of its containing
23142308module. Items, such as those declared with ` fn ` , ` struct ` , ` enum ` ,
2315- ` type ` , or ` const ` , are module-private by default.
2309+ ` type ` , or ` static ` , are module-private by default.
23162310
23172311Visibility restrictions in Rust exist only at module boundaries. This
23182312is quite different from most object-oriented languages that also
0 commit comments