Skip to content

Commit c4553ca

Browse files
committed
Merge pull request #1554 from rtanglao/master
rustdocs for box.rs, comm.rs, ctypes.rs, char.rs
2 parents 65e3c35 + 93be00f commit c4553ca

File tree

4 files changed

+165
-267
lines changed

4 files changed

+165
-267
lines changed

src/libcore/box.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
/*
2-
Module: box
3-
*/
4-
5-
61
export ptr_eq;
72

8-
/*
9-
Function: ptr_eq
10-
11-
Determine if two shared boxes point to the same object
12-
*/
3+
#[doc(
4+
brief = "Determine if two shared boxes point to the same object"
5+
)]
136
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
147
// FIXME: ptr::addr_of
158
unsafe {

src/libcore/char.rs

+40-74
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/*
2-
Module: char
3-
4-
Utilities for manipulating the char type
5-
*/
1+
#[doc = "Utilities for manipulating the char type"];
62

73
/*
84
Lu Uppercase_Letter an uppercase letter
@@ -47,50 +43,40 @@ import is_alphabetic = unicode::derived_property::Alphabetic;
4743
import is_XID_start = unicode::derived_property::XID_Start;
4844
import is_XID_continue = unicode::derived_property::XID_Continue;
4945

50-
/*
51-
Function: is_lowercase
5246

53-
Indicates whether a character is in lower case, defined in terms of the
54-
Unicode General Category 'Ll'.
55-
*/
47+
#[doc(
48+
brief = "Indicates whether a character is in lower case, defined \
49+
in terms of the Unicode General Category 'Ll'."
50+
)]
5651
pure fn is_lowercase(c: char) -> bool {
5752
ret unicode::general_category::Ll(c);
5853
}
5954

60-
/*
61-
Function: is_uppercase
62-
63-
Indicates whether a character is in upper case, defined in terms of the
64-
Unicode General Category 'Lu'.
65-
*/
55+
#[doc(
56+
brief = "Indicates whether a character is in upper case, defined \
57+
in terms of the Unicode General Category 'Lu'."
58+
)]
6659
pure fn is_uppercase(c: char) -> bool {
6760
ret unicode::general_category::Lu(c);
6861
}
6962

70-
/*
71-
Function: is_whitespace
72-
73-
Indicates whether a character is whitespace, defined in terms of
74-
the Unicode General Categories 'Zs', 'Zl', 'Zp' and the additional
75-
'Cc'-category control codes in the range [0x09, 0x0d].
76-
77-
*/
63+
#[doc(
64+
brief = "Indicates whether a character is whitespace, defined in \
65+
terms of the Unicode General Categories 'Zs', 'Zl', 'Zp' \
66+
additional 'Cc'-category control codes in the range [0x09, 0x0d]"
67+
)]
7868
pure fn is_whitespace(c: char) -> bool {
7969
ret ('\x09' <= c && c <= '\x0d')
8070
|| unicode::general_category::Zs(c)
8171
|| unicode::general_category::Zl(c)
8272
|| unicode::general_category::Zp(c);
8373
}
8474

85-
/*
86-
Function: is_alphanumeric
87-
88-
Indicates whether a character is alphanumeric, defined in terms of
89-
the Unicode General Categories 'Nd', 'Nl', 'No' and the Derived
90-
Core Property 'Alphabetic'.
91-
92-
*/
93-
75+
#[doc(
76+
brief = "Indicates whether a character is alphanumeric, defined \
77+
in terms of the Unicode General Categories 'Nd', \
78+
'Nl', 'No' and the Derived Core Property 'Alphabetic'."
79+
)]
9480
pure fn is_alphanumeric(c: char) -> bool {
9581
ret unicode::derived_property::Alphabetic(c) ||
9682
unicode::general_category::Nd(c) ||
@@ -99,34 +85,24 @@ pure fn is_alphanumeric(c: char) -> bool {
9985
}
10086

10187

102-
/*
103-
Function: to_digit
104-
105-
Convert a char to the corresponding digit.
106-
107-
Parameters:
108-
c - a char, either '0' to '9', 'a' to 'z' or 'A' to 'Z'
109-
110-
Returns:
111-
If `c` is between '0' and '9', the corresponding value between 0 and 9.
112-
If `c` is 'a' or 'A', 10. If `c` is 'b' or 'B', 11, etc.
113-
114-
Safety note:
115-
This function fails if `c` is not a valid char
116-
*/
88+
#[doc(
89+
brief = "Convert a char to the corresponding digit. \
90+
Safety note: This function fails if `c` is not a valid char",
91+
return = "If `c` is between '0' and '9', the corresponding value \
92+
between 0 and 9. If `c` is 'a' or 'A', 10. If `c` is \
93+
'b' or 'B', 11, etc."
94+
)]
11795
pure fn to_digit(c: char) -> u8 unsafe {
11896
alt maybe_digit(c) {
11997
option::some(x) { x }
12098
option::none. { fail; }
12199
}
122100
}
123101

124-
/*
125-
Function: maybe_digit
126-
127-
Convert a char to the corresponding digit. Returns none when the
128-
character is not a valid hexadecimal digit.
129-
*/
102+
#[doc(
103+
brief = "Convert a char to the corresponding digit. Returns none when \
104+
character is not a valid hexadecimal digit."
105+
)]
130106
pure fn maybe_digit(c: char) -> option::t<u8> {
131107
alt c {
132108
'0' to '9' { option::some(c as u8 - ('0' as u8)) }
@@ -137,12 +113,11 @@ pure fn maybe_digit(c: char) -> option::t<u8> {
137113
}
138114

139115
/*
140-
Function: to_lower
141-
142-
Convert a char to the corresponding lower case.
143-
144116
FIXME: works only on ASCII
145117
*/
118+
#[doc(
119+
brief = "Convert a char to the corresponding lower case."
120+
)]
146121
pure fn to_lower(c: char) -> char {
147122
alt c {
148123
'A' to 'Z' { ((c as u8) + 32u8) as char }
@@ -151,31 +126,22 @@ pure fn to_lower(c: char) -> char {
151126
}
152127

153128
/*
154-
Function: to_upper
155-
156-
Convert a char to the corresponding upper case.
157-
158129
FIXME: works only on ASCII
159130
*/
131+
#[doc(
132+
brief = "Convert a char to the corresponding upper case."
133+
)]
160134
pure fn to_upper(c: char) -> char {
161135
alt c {
162136
'a' to 'z' { ((c as u8) - 32u8) as char }
163137
_ { c }
164138
}
165139
}
166140

167-
/*
168-
Function: cmp
169-
170-
Compare two chars.
171-
172-
Parameters:
173-
a - a char
174-
b - a char
175-
176-
Returns:
177-
-1 if a<b, 0 if a==b, +1 if a>b
178-
*/
141+
#[doc(
142+
brief = "Compare two chars.",
143+
return = "-1 if a<b, 0 if a==b, +1 if a>b"
144+
)]
179145
pure fn cmp(a: char, b: char) -> int {
180146
ret if b > a { -1 }
181147
else if b < a { 1 }

src/libcore/comm.rs

+58-81
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
/*
2-
Module: comm
3-
4-
Communication between tasks
5-
6-
Communication between tasks is facilitated by ports (in the receiving task),
7-
and channels (in the sending task). Any number of channels may feed into a
8-
single port.
9-
10-
Ports and channels may only transmit values of unique types; that is,
11-
values that are statically guaranteed to be accessed by a single
12-
'owner' at a time. Unique types include scalars, vectors, strings,
13-
and records, tags, tuples and unique boxes (~T) thereof. Most notably,
14-
shared boxes (@T) may not be transmitted across channels.
15-
16-
Example:
17-
18-
> let p = comm::port();
19-
> task::spawn(comm::chan(p), fn (c: chan<str>) {
20-
> comm::send(c, "Hello, World");
21-
> });
22-
>
23-
> io::println(comm::recv(p));
24-
25-
*/
1+
#[doc(
2+
brief = "Communication between tasks",
3+
desc = "Communication between tasks is facilitated by ports (in the \
4+
receiving task), and channels (in the sending task). Any \
5+
number of channels may feed into a single port. \
6+
Ports and channels may only transmit values of unique \
7+
types; that is, values that are statically guaranteed to \
8+
be accessed by a single 'owner' at a time. Unique types \
9+
include scalars, vectors, strings, and records, tags, \
10+
tuples and unique boxes (~T) thereof. Most notably, \
11+
shared boxes (@T) may not be transmitted across channels. \
12+
Example: \
13+
let p = comm::port(); \
14+
task::spawn(comm::chan(p), fn (c: chan<str>) { \
15+
comm::send(c, \"Hello, World\"); \
16+
}); \
17+
io::println(comm::recv(p));"
18+
)];
2619

2720
import sys;
2821
import task;
@@ -59,22 +52,18 @@ type port_id = int;
5952

6053
// It's critical that this only have one variant, so it has a record
6154
// layout, and will work in the rust_task structure in task.rs.
62-
/*
63-
Type: chan
64-
65-
A communication endpoint that can send messages. Channels send
66-
messages to ports.
67-
68-
Each channel is bound to a port when the channel is constructed, so
69-
the destination port for a channel must exist before the channel
70-
itself.
71-
72-
Channels are weak: a channel does not keep the port it is bound to alive.
73-
If a channel attempts to send data to a dead port that data will be silently
74-
dropped.
75-
76-
Channels may be duplicated and themselves transmitted over other channels.
77-
*/
55+
#[doc(
56+
brief = "A communication endpoint that can send messages. \
57+
Channels send messages to ports.",
58+
desc = "Each channel is bound to a port when the channel is \
59+
constructed, so the destination port for a channel \
60+
must exist before the channel itself. \
61+
Channels are weak: a channel does not keep the port it \
62+
is bound to alive. If a channel attempts to send data \
63+
to a dead port that data will be silently dropped. \
64+
Channels may be duplicated and themselves transmitted \
65+
over other channels."
66+
)]
7867
tag chan<T: send> {
7968
chan_t(task::task, port_id);
8069
}
@@ -92,27 +81,21 @@ resource port_ptr<T: send>(po: *rustrt::rust_port) {
9281
rustrt::del_port(po);
9382
}
9483

95-
/*
96-
Type: port
97-
98-
A communication endpoint that can receive messages. Ports receive
99-
messages from channels.
100-
101-
Each port has a unique per-task identity and may not be replicated or
102-
transmitted. If a port value is copied, both copies refer to the same port.
103-
104-
Ports may be associated with multiple <chan>s.
105-
*/
84+
#[doc(
85+
brief = "A communication endpoint that can receive messages. \
86+
Ports receive messages from channels.",
87+
desc = "Each port has a unique per-task identity and may not \
88+
be replicated or transmitted. If a port value is \
89+
copied, both copies refer to the same port. \
90+
Ports may be associated with multiple <chan>s."
91+
)]
10692
tag port<T: send> { port_t(@port_ptr<T>); }
10793

108-
/*
109-
Function: send
110-
111-
Sends data over a channel.
112-
113-
The sent data is moved into the channel, whereupon the caller loses access
114-
to it.
115-
*/
94+
#[doc(
95+
brief = "Sends data over a channel. The sent data is moved \
96+
into the channel, whereupon the caller loses \
97+
access to it."
98+
)]
11699
fn send<T: send>(ch: chan<T>, -data: T) {
117100
let chan_t(t, p) = ch;
118101
let res = rustrt::chan_id_send(sys::get_type_desc::<T>(), t, p, data);
@@ -123,26 +106,23 @@ fn send<T: send>(ch: chan<T>, -data: T) {
123106
task::yield();
124107
}
125108

126-
/*
127-
Function: port
128-
129-
Constructs a port.
130-
*/
109+
#[doc(
110+
brief = "Constructs a port."
111+
)]
131112
fn port<T: send>() -> port<T> {
132113
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
133114
}
134115

135-
/*
136-
Function: recv
137-
138-
Receive from a port.
139-
140-
If no data is available on the port then the task will block until data
141-
becomes available.
142-
*/
116+
#[doc(
117+
brief = "Receive from a port. \
118+
If no data is available on the port then the task will \
119+
block until data becomes available."
120+
)]
143121
fn recv<T: send>(p: port<T>) -> T { recv_(***p) }
144122

145-
// Receive on a raw port pointer
123+
#[doc(
124+
brief = "Receive on a raw port pointer"
125+
)]
146126
fn recv_<T: send>(p: *rustrt::rust_port) -> T {
147127
// FIXME: Due to issue 1185 we can't use a return pointer when
148128
// calling C code, and since we can't create our own return
@@ -169,13 +149,10 @@ fn recv_<T: send>(p: *rustrt::rust_port) -> T {
169149
ret res;
170150
}
171151

172-
/*
173-
Function: chan
174-
175-
Constructs a channel.
176-
177-
The channel is bound to the port used to construct it.
178-
*/
152+
#[doc(
153+
brief = "Constructs a channel. The channel is bound to the \
154+
port used to construct it."
155+
)]
179156
fn chan<T: send>(p: port<T>) -> chan<T> {
180157
chan_t(task::get_task(), rustrt::get_port_id(***p))
181158
}

0 commit comments

Comments
 (0)