@@ -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 ] ?
@@ -1006,25 +1006,20 @@ code_. They are defined in the same way as any other Rust function,
1006
1006
except that they have the ` extern ` modifier.
1007
1007
1008
1008
~~~
1009
- // Declares an extern fn, the ABI defaults to "C"
1010
1009
extern fn new_vec() -> ~[int] { ~[] }
1011
-
1012
- // Declares an extern fn with "stdcall" ABI
1013
- extern "stdcall" fn new_vec_stdcall() -> ~[int] { ~[] }
1014
1010
~~~
1015
1011
1016
- Unlike normal functions, extern fns have an ` extern "ABI" fn() ` .
1017
- This is the same type as the functions declared in an extern
1018
- block.
1012
+ Extern functions may not be called from Rust code,
1013
+ but Rust code may take their value as a raw ` u8 ` pointer.
1019
1014
1020
1015
~~~
1021
1016
# extern fn new_vec() -> ~[int] { ~[] }
1022
- let fptr: extern "C" fn() -> ~[int] = new_vec;
1017
+ let fptr: *u8 = new_vec;
1023
1018
~~~
1024
1019
1025
- Extern functions may be called from Rust code, but
1026
- caution must be taken with respect to the size of the stack
1027
- 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 .
1028
1023
1029
1024
### Type definitions
1030
1025
@@ -1389,13 +1384,14 @@ between the Rust ABI and the foreign ABI.
1389
1384
A number of [ attributes] ( #attributes ) control the behavior of external
1390
1385
blocks.
1391
1386
1392
- By default external blocks assume that the library they are calling
1393
- uses the standard C "cdecl" ABI. Other ABIs may be specified using
1394
- 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
1395
1390
1396
1391
~~~ {.xfail-test}
1397
1392
// Interface to the Windows API
1398
- extern "stdcall" { }
1393
+ #[abi = "stdcall"]
1394
+ extern { }
1399
1395
~~~
1400
1396
1401
1397
The ` link_name ` attribute allows the name of the library to be specified.
@@ -1411,12 +1407,6 @@ This is particularly useful for creating external blocks for libc,
1411
1407
which tends to not follow standard library naming conventions
1412
1408
and is linked to all Rust programs anyway.
1413
1409
1414
- The type of a function
1415
- declared in an extern block
1416
- is ` extern "abi" fn(A1, ..., An) -> R ` ,
1417
- where ` A1...An ` are the declared types of its arguments
1418
- and ` R ` is the decalred return type.
1419
-
1420
1410
## Attributes
1421
1411
1422
1412
~~~~~~~~ {.ebnf .gram}
@@ -1930,7 +1920,7 @@ it is automatically dereferenced to make the field access possible.
1930
1920
### Vector expressions
1931
1921
1932
1922
~~~~~~~~ {.ebnf .gram}
1933
- vec_expr : '[' "mut" ? vec_elems? ']'
1923
+ vec_expr : '[' "mut"? vec_elems? ']'
1934
1924
1935
1925
vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
1936
1926
~~~~~~~~
@@ -2874,16 +2864,17 @@ the vtable pointer for the `T` implementation of `R`, and the pointer value of `
2874
2864
An example of an object type:
2875
2865
2876
2866
~~~~~~~~
2867
+ # use std::int;
2877
2868
trait Printable {
2878
- fn to_string (&self) -> ~str;
2869
+ fn to_str (&self) -> ~str;
2879
2870
}
2880
2871
2881
2872
impl Printable for int {
2882
- fn to_string (&self) -> ~str { self. to_str() }
2873
+ fn to_str (&self) -> ~str { int:: to_str(*self ) }
2883
2874
}
2884
2875
2885
2876
fn print(a: @Printable) {
2886
- println(a.to_string ());
2877
+ println(a.to_str ());
2887
2878
}
2888
2879
2889
2880
fn main() {
0 commit comments