Skip to content

Commit 95feaee

Browse files
committed
In doc reference, don't mention references, and stub out a section for classes
1 parent bf92940 commit 95feaee

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

doc/rust.md

+26-16
Original file line numberDiff line numberDiff line change
@@ -1127,30 +1127,40 @@ enum list<T> {
11271127
let a: list<int> = cons(7, @cons(13, @nil));
11281128
~~~~
11291129

1130-
### Resources
1130+
### Classes
11311131

1132-
_Resources_ are values that have a destructor associated with them. A
1133-
_resource item_ is used to declare resource type and constructor.
1132+
TODO: more about classes
1133+
1134+
_Classes_ are named record types that may have a destructor associated
1135+
with them, as well as fields and methods. For historical reasons, we
1136+
may call a class with a destructor and a single field a "resource".
1137+
1138+
A _class item_ declares a class type:
11341139

11351140
~~~~
1136-
resource file_descriptor(fd: libc::c_int) {
1137-
libc::close(fd);
1141+
class file_descriptor {
1142+
let fd: libc::c_int;
1143+
new(fd: libc::c_int) { self.fd = fd; }
1144+
drop { libc::close(self.fd); }
11381145
}
11391146
~~~~
11401147

11411148
Calling the `file_descriptor` constructor function on an integer will
11421149
produce a value with the `file_descriptor` type. Resource types have a
1143-
noncopyable [type kind](#type-kinds), and thus may not be copied. The
1144-
semantics guarantee that for each constructed resources value, the
1145-
destructor will run once: when the value is disposed of (barring
1146-
drastic program termination that somehow prevents unwinding from taking
1147-
place). For stack-allocated values, disposal happens when the value
1148-
goes out of scope. For values in shared boxes, it happens when the
1149-
reference count of the box reaches zero.
1150-
1151-
The argument to the resource constructor is stored in the resulting
1152-
value, and can be accessed using the dereference (`*`) [unary
1153-
operator](#unary-operator-expressions).
1150+
noncopyable [type kind](#type-kinds), and thus may not be
1151+
copied. Class types that don't have destructors may be copied if all
1152+
their fields are copyable. The semantics guarantee that for each
1153+
constructed resource value, the destructor will run once: when the
1154+
value is disposed of (barring drastic program termination that somehow
1155+
prevents unwinding from taking place). For stack-allocated values,
1156+
disposal happens when the value goes out of scope. For values in
1157+
shared boxes, it happens when the reference count of the box reaches
1158+
zero.
1159+
1160+
The argument or arguments to the class constructor may be stored in
1161+
the class's named fields, and can be accessed by a field reference. In
1162+
this case, the `file_descriptor`'s data field would be accessed like
1163+
`f.fd`, if `f` is a value of type `file_descriptor`.
11541164

11551165
### Interfaces
11561166

0 commit comments

Comments
 (0)