@@ -788,7 +788,7 @@ extern mod complicated_mod = "some-file/in/the-rust/path";
788
788
##### Use declarations
789
789
790
790
~~~~~~~~ {.ebnf .gram}
791
- use_decl : "pub" ? "use" ident [ '=' path
791
+ use_decl : "pub"? "use" ident [ '=' path
792
792
| "::" path_glob ] ;
793
793
794
794
path_glob : ident [ "::" path_glob ] ?
@@ -851,38 +851,6 @@ In this example, the module `quux` re-exports all of the public names defined in
851
851
852
852
Also note that the paths contained in ` use ` items are relative to the crate root.
853
853
So, in the previous example, the ` use ` refers to ` quux::foo::* ` , and not simply to ` foo::* ` .
854
- This also means that top-level module declarations should be at the crate root if direct usage
855
- of the declared modules within ` use ` items is desired. It is also possible to use ` self ` and ` super `
856
- at the beginning of a ` use ` item to refer to the current and direct parent modules respectively.
857
- All rules regarding accessing declared modules in ` use ` declarations applies to both module declarations
858
- and ` extern mod ` declarations.
859
-
860
- An example of what will and will not work for ` use ` items:
861
- ~~~~
862
- # #[allow(unused_imports)];
863
- use foo::extra; // good: foo is at the root of the crate
864
- use foo::baz::foobaz; // good: foo is at the root of the crate
865
-
866
- mod foo {
867
- extern mod extra;
868
-
869
- use foo::extra::list; // good: foo is at crate root
870
- // use extra::*; // bad: extra is not at the crate root
871
- use self::baz::foobaz; // good: self refers to module 'foo'
872
- use foo::bar::foobar; // good: foo is at crate root
873
-
874
- pub mod bar {
875
- pub fn foobar() { }
876
- }
877
-
878
- pub mod baz {
879
- use super::bar::foobar; // good: super refers to module 'foo'
880
- pub fn foobaz() { }
881
- }
882
- }
883
-
884
- fn main() {}
885
- ~~~~
886
854
887
855
### Functions
888
856
@@ -1038,25 +1006,20 @@ code_. They are defined in the same way as any other Rust function,
1038
1006
except that they have the ` extern ` modifier.
1039
1007
1040
1008
~~~
1041
- // Declares an extern fn, the ABI defaults to "C"
1042
1009
extern fn new_vec() -> ~[int] { ~[] }
1043
-
1044
- // Declares an extern fn with "stdcall" ABI
1045
- extern "stdcall" fn new_vec_stdcall() -> ~[int] { ~[] }
1046
1010
~~~
1047
1011
1048
- Unlike normal functions, extern fns have an ` extern "ABI" fn() ` .
1049
- This is the same type as the functions declared in an extern
1050
- block.
1012
+ Extern functions may not be called from Rust code,
1013
+ but Rust code may take their value as a raw ` u8 ` pointer.
1051
1014
1052
1015
~~~
1053
1016
# extern fn new_vec() -> ~[int] { ~[] }
1054
- let fptr: extern "C" fn() -> ~[int] = new_vec;
1017
+ let fptr: *u8 = new_vec;
1055
1018
~~~
1056
1019
1057
- Extern functions may be called from Rust code, but
1058
- caution must be taken with respect to the size of the stack
1059
- segment, just as when calling an extern function normally .
1020
+ The primary motivation for extern functions is
1021
+ to create callbacks for foreign functions that expect to receive function
1022
+ pointers .
1060
1023
1061
1024
### Type definitions
1062
1025
@@ -1421,13 +1384,14 @@ between the Rust ABI and the foreign ABI.
1421
1384
A number of [ attributes] ( #attributes ) control the behavior of external
1422
1385
blocks.
1423
1386
1424
- By default external blocks assume that the library they are calling
1425
- uses the standard C "cdecl" ABI. Other ABIs may be specified using
1426
- an ` abi ` string, as shown here:
1387
+ By default external blocks assume
1388
+ that the library they are calling uses the standard C "cdecl" ABI.
1389
+ Other ABIs may be specified using the ` abi ` attribute as in
1427
1390
1428
1391
~~~ {.xfail-test}
1429
1392
// Interface to the Windows API
1430
- extern "stdcall" { }
1393
+ #[abi = "stdcall"]
1394
+ extern { }
1431
1395
~~~
1432
1396
1433
1397
The ` link_name ` attribute allows the name of the library to be specified.
@@ -1443,12 +1407,6 @@ This is particularly useful for creating external blocks for libc,
1443
1407
which tends to not follow standard library naming conventions
1444
1408
and is linked to all Rust programs anyway.
1445
1409
1446
- The type of a function
1447
- declared in an extern block
1448
- is ` extern "abi" fn(A1, ..., An) -> R ` ,
1449
- where ` A1...An ` are the declared types of its arguments
1450
- and ` R ` is the decalred return type.
1451
-
1452
1410
## Attributes
1453
1411
1454
1412
~~~~~~~~ {.ebnf .gram}
@@ -1962,7 +1920,7 @@ it is automatically dereferenced to make the field access possible.
1962
1920
### Vector expressions
1963
1921
1964
1922
~~~~~~~~ {.ebnf .gram}
1965
- vec_expr : '[' "mut" ? vec_elems? ']'
1923
+ vec_expr : '[' "mut"? vec_elems? ']'
1966
1924
1967
1925
vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
1968
1926
~~~~~~~~
@@ -2906,16 +2864,17 @@ the vtable pointer for the `T` implementation of `R`, and the pointer value of `
2906
2864
An example of an object type:
2907
2865
2908
2866
~~~~~~~~
2867
+ # use std::int;
2909
2868
trait Printable {
2910
- fn to_string (&self) -> ~str;
2869
+ fn to_str (&self) -> ~str;
2911
2870
}
2912
2871
2913
2872
impl Printable for int {
2914
- fn to_string (&self) -> ~str { self. to_str() }
2873
+ fn to_str (&self) -> ~str { int:: to_str(*self ) }
2915
2874
}
2916
2875
2917
2876
fn print(a: @Printable) {
2918
- println(a.to_string ());
2877
+ println(a.to_str ());
2919
2878
}
2920
2879
2921
2880
fn main() {
0 commit comments