Skip to content

Commit 89efb7d

Browse files
committed
libstd: Update docs
1 parent baf3de4 commit 89efb7d

File tree

10 files changed

+178
-13
lines changed

10 files changed

+178
-13
lines changed

doc/Languages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Language: Rust
120120
Block Comment: /* */
121121
Package Separator: ::
122122
Function Prototype Enders: ; {
123+
Predicate Prototype Enders: ; {
123124
Type Prototype Enders: ; }
124125
Class Prototype Enders: {
125126
Variant Prototype Enders: ;

src/libstd/c_vec.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,36 @@ resource dtor_res(dtor: option::t<fn@()>) {
5757
Section: Introduction forms
5858
*/
5959

60+
/*
61+
Function: create
62+
63+
Create a c_vec::t from a native buffer with a given size.
64+
65+
Parameters:
66+
67+
base - A native pointer to a buffer
68+
size - The number of elements in the buffer
69+
*/
6070
unsafe fn create<T>(base: *mutable T, size: uint) -> t<T> {
6171
ret t({base: base,
6272
size: size,
6373
rsrc: @dtor_res(option::none)
6474
});
6575
}
6676

77+
/*
78+
Function: create_with_dtor
79+
80+
Create a c_vec::t from a native buffer, with a given size,
81+
and a function to run upon destruction.
82+
83+
Parameters:
84+
85+
base - A native pointer to a buffer
86+
size - The number of elements in the buffer
87+
dtor - A function to run when the value is destructed, useful
88+
for freeing the buffer, etc.
89+
*/
6790
unsafe fn create_with_dtor<T>(base: *mutable T, size: uint, dtor: fn@())
6891
-> t<T> {
6992
ret t({base: base,
@@ -76,11 +99,29 @@ unsafe fn create_with_dtor<T>(base: *mutable T, size: uint, dtor: fn@())
7699
Section: Operations
77100
*/
78101

102+
/*
103+
Function: get
104+
105+
Retrieves an element at a given index
106+
107+
Failure:
108+
109+
If `ofs` is greater or equal to the length of the vector
110+
*/
79111
fn get<copy T>(t: t<T>, ofs: uint) -> T {
80112
assert ofs < (*t).size;
81113
ret unsafe { *ptr::mut_offset((*t).base, ofs) };
82114
}
83115

116+
/*
117+
Function: set
118+
119+
Sets the value of an element at a given index
120+
121+
Failure:
122+
123+
If `ofs` is greater or equal to the length of the vector
124+
*/
84125
fn set<copy T>(t: t<T>, ofs: uint, v: T) {
85126
assert ofs < (*t).size;
86127
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
@@ -90,10 +131,21 @@ fn set<copy T>(t: t<T>, ofs: uint, v: T) {
90131
Section: Elimination forms
91132
*/
92133

134+
// FIXME: Rename to len
135+
/*
136+
Function: size
137+
138+
Returns the length of the vector
139+
*/
93140
fn size<T>(t: t<T>) -> uint {
94141
ret (*t).size;
95142
}
96143

144+
/*
145+
Function: ptr
146+
147+
Returns a pointer to the first element of the vector
148+
*/
97149
unsafe fn ptr<T>(t: t<T>) -> *mutable T {
98150
ret (*t).base;
99151
}

src/libstd/ctypes.rs

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,143 @@ Module: ctypes
44
Definitions useful for C interop
55
*/
66

7+
/*
8+
FIXME: Add a test that uses some native code to verify these sizes,
9+
which are not obviously correct for all potential platforms.
10+
*/
11+
12+
/*
13+
Type: c_int
14+
15+
A signed integer with the same size as a C `int`
16+
*/
717
type c_int = i32;
18+
19+
/*
20+
Type: c_uint
21+
22+
An unsigned integer with the same size as a C `unsigned int`
23+
*/
824
type c_uint = u32;
925

10-
type void = int; // Not really the same as C
26+
/*
27+
Type: long
28+
29+
A signed integer with the same size as a C `long`
30+
*/
1131
type long = int;
32+
33+
/*
34+
Type: unsigned
35+
36+
An unsigned integer with the same size as a C `unsigned int`
37+
*/
1238
type unsigned = u32;
39+
40+
/*
41+
Type: ulong
42+
43+
An unsigned integer with the same size as a C `unsigned long`
44+
*/
1345
type ulong = uint;
1446

15-
type intptr_t = uint;
47+
/*
48+
Type: intptr_t
49+
50+
A signed integer with the same size as a pointer. This is
51+
guaranteed to always be the same type as a Rust `int`
52+
*/
53+
type intptr_t = uint; // FIXME: int
54+
55+
/*
56+
Type: uintptr_t
57+
58+
An unsigned integer with the same size as a pointer. This is
59+
guaranteed to always be the same type as a Rust `uint`.
60+
*/
1661
type uintptr_t = uint;
1762
type uint32_t = u32;
1863

64+
/*
65+
Type: void
66+
67+
A type, a pointer to which can be used as C `void *`
68+
69+
Note that this does not directly correspond to the C `void` type,
70+
which is an incomplete type. Using pointers to this type
71+
when interoperating with C void pointers can help in documentation.
72+
*/
73+
type void = int;
74+
1975
// machine type equivalents of rust int, uint, float
2076

77+
/*
78+
Type: m_int
79+
80+
FIXME: What C type does this represent?
81+
*/
2182
#[cfg(target_arch="x86")]
2283
type m_int = i32;
2384
#[cfg(target_arch="x86_64")]
2485
type m_int = i64;
2586

87+
/*
88+
Type: m_uint
89+
90+
FIXME: What C type does this represent?
91+
*/
2692
#[cfg(target_arch="x86")]
2793
type m_uint = u32;
2894
#[cfg(target_arch="x86_64")]
2995
type m_uint = u64;
3096

3197
// This *must* match with "import m_float = fXX" in std::math per arch
98+
/*
99+
Type: m_float
100+
101+
FIXME: What C type does this represent?
102+
*/
32103
type m_float = f64;
33104

105+
/*
106+
Type: size_t
107+
108+
An unsigned integer corresponding to the C `size_t`
109+
*/
34110
type size_t = uint;
111+
112+
/*
113+
Type: ssize_t
114+
115+
A signed integer correpsonding to the C `ssize_t`
116+
*/
35117
type ssize_t = int;
118+
119+
/*
120+
Type: off_t
121+
122+
An unsigned integer corresponding to the C `off_t`
123+
*/
36124
type off_t = uint;
37125

126+
/*
127+
Type: fd_t
128+
129+
A type that can be used for C file descriptors
130+
*/
38131
type fd_t = i32; // not actually a C type, but should be.
132+
133+
/*
134+
Type: pid_t
135+
136+
A type for representing process ID's, corresponding to C `pid_t`
137+
*/
39138
type pid_t = i32;
40139

41140
// enum is implementation-defined, but is 32-bits in practice
141+
/*
142+
Type: enum
143+
144+
An unsigned integer with the same size as a C enum
145+
*/
42146
type enum = u32;

src/libstd/float.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,25 +253,18 @@ fn pow_uint_to_uint_as_float(x: uint, pow: uint) -> float {
253253
}
254254

255255

256-
/**
257-
* Section: Constants
258-
*/
259-
260-
//TODO: Once this is possible, replace the body of these functions
261-
//by an actual constant.
262-
263256
/* Const: NaN */
264257
const NaN: float = 0./0.;
265258

266-
/* Predicate: isNaN */
267-
pure fn isNaN(f: float) -> bool { f != f }
268-
269259
/* Const: infinity */
270260
const infinity: float = 1./0.;
271261

272262
/* Const: neg_infinity */
273263
const neg_infinity: float = -1./0.;
274264

265+
/* Predicate: isNaN */
266+
pure fn isNaN(f: float) -> bool { f != f }
267+
275268
/* Function: add */
276269
pure fn add(x: float, y: float) -> float { ret x + y; }
277270

src/libstd/io.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
Module: io
3+
4+
Basic input/output
5+
*/
6+
17
import ctypes::fd_t;
28
import ctypes::c_int;
39

src/libstd/math.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import ctypes::c_int;
2323
import m_float = math_f64;
2424

2525
// FIXME replace with redirect to m_float::consts::FOO as soon as it works
26+
/*
27+
Module: consts
28+
*/
2629
mod consts {
2730
/*
2831
Const: pi

src/libstd/math_f32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export
1717

1818
export consts;
1919

20+
/* Module: consts */
2021
mod consts {
2122

2223
/*

src/libstd/math_f64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export
1717

1818
export consts;
1919

20+
/* Module: consts */
2021
mod consts {
2122

2223
/*

src/libstd/str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ fn byte_len_range(s: str, byte_offset: uint, char_len: uint) -> uint {
174174
/*
175175
Function: bytes
176176
177-
Converts a string to a vector of bytes
177+
Converts a string to a vector of bytes. The result vector is not
178+
null-terminated.
178179
*/
179180
fn bytes(s: str) -> [u8] unsafe {
180181
let v = unsafe::reinterpret_cast(s);

src/libstd/tempfile.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import option;
99
import option::{none, some};
1010
import rand;
1111

12+
/*
13+
Function: mkdtemp
14+
*/
1215
fn mkdtemp(prefix: str, suffix: str) -> option::t<str> {
1316
let r = rand::mk_rng();
1417
let i = 0u;

0 commit comments

Comments
 (0)