Skip to content

Commit 070b271

Browse files
committed
---
yaml --- r: 147167 b: refs/heads/try2 c: f41b4e3 h: refs/heads/master i: 147165: 559cf93 147163: de4d5a7 147159: bae9ee4 147151: 5bf74b4 147135: 25f3863 v: v3
1 parent 52bd5c5 commit 070b271

File tree

212 files changed

+3373
-2021
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+3373
-2021
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: f39c883598ca937b8b84720f184cdf370daf107d
8+
refs/heads/try2: f41b4e351b4fface2ad3c4b74912837c4059d56a
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rustdoc.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
% Rust Documentation
2+
3+
`rustdoc` is the built-in tool for generating documentation. It integrates
4+
with the compiler to provide accurate hyperlinking between usage of types and
5+
their documentation. Furthermore, by not using a separate parser, it will
6+
never reject your valid Rust code.
7+
8+
# Creating Documentation
9+
10+
Documenting Rust APIs is quite simple. To document a given item, we have "doc
11+
comments":
12+
13+
~~~
14+
// the "link" crate attribute is currently required for rustdoc, but normally
15+
// isn't needed.
16+
#[link(name="universe")];
17+
#[crate_type="lib"];
18+
19+
//! Tools for dealing with universes (this is a doc comment, and is shown on
20+
//! the crate index page. The ! makes it apply to the parent of the comment,
21+
//! rather than what follows).
22+
23+
/// Widgets are very common (this is a doc comment, and will show up on
24+
/// Widget's documentation).
25+
pub struct Widget {
26+
/// All widgets have a purpose (this is a doc comment, and will show up
27+
/// the field's documentation).
28+
purpose: ~str,
29+
/// Humans are not allowed to understand some widgets
30+
understandable: bool
31+
}
32+
33+
pub fn recalibrate() {
34+
//! Recalibrate a pesky universe (this is also a doc comment, like above,
35+
//! the documentation will be applied to the *parent* item, so
36+
//! `recalibrate`).
37+
/* ... */
38+
}
39+
~~~
40+
41+
Then, one can run `rustdoc universe.rs`. By default, it generates a directory
42+
called `doc`, with the documentation for `universe` being in
43+
`doc/universe/index.html`. If you are using other crates with `extern mod`,
44+
rustdoc will even link to them when you use their types, as long as their
45+
documentation has already been generated by a previous run of rustdoc, or the
46+
crate advertises that its documentation is hosted at a given URL.
47+
48+
The generated output can be controlled with the `doc` crate attribute, which
49+
is how the above advertisement works. An example from the `libstd`
50+
documentation:
51+
52+
~~~
53+
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
54+
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
55+
html_root_url = "http://static.rust-lang.org/doc/master")];
56+
~~~
57+
58+
The `html_root_url` is the prefix that rustdoc will apply to any references to
59+
that crate's types etc.
60+
61+
rustdoc can also generate JSON, for consumption by other tools, with
62+
`rustdoc --output-format json`, and also consume already-generated JSON with
63+
`rustdoc --input-format json`.
64+
65+
# Using the Documentation
66+
67+
The web pages generated by rustdoc present the same logical heirarchy that one
68+
writes a library with. Every kind of item (function, struct, etc) has its own
69+
color, and one can always click on a colored type to jump to its
70+
documentation. There is a search bar at the top, which is powered by some
71+
javascript and a statically-generated search index. No special web server is
72+
required for the search.

branches/try2/doc/tutorial-ffi.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ for the rust task is plenty for the C function to have.
152152

153153
A planned future improvement (net yet implemented at the time of this writing)
154154
is to have a guard page at the end of every rust stack. No rust function will
155-
hit this guard page (due to rust's usage of LLVM's __morestack). The intention
155+
hit this guard page (due to Rust's usage of LLVM's `__morestack`). The intention
156156
for this unmapped page is to prevent infinite recursion in C from overflowing
157157
onto other rust stacks. If the guard page is hit, then the process will be
158158
terminated with a message saying that the guard page was hit.
@@ -166,30 +166,39 @@ the stack of the task which is spawned.
166166

167167
# Destructors
168168

169-
Foreign libraries often hand off ownership of resources to the calling code,
170-
which should be wrapped in a destructor to provide safety and guarantee their
171-
release.
169+
Foreign libraries often hand off ownership of resources to the calling code.
170+
When this occurs, we must use Rust's destructors to provide safety and guarantee
171+
the release of these resources (especially in the case of failure).
172172

173-
A type with the same functionality as owned boxes can be implemented by
174-
wrapping `malloc` and `free`:
173+
As an example, we give a reimplementation of owned boxes by wrapping `malloc`
174+
and `free`:
175175

176176
~~~~
177177
use std::cast;
178178
use std::libc::{c_void, size_t, malloc, free};
179179
use std::ptr;
180180
use std::unstable::intrinsics;
181181
182-
// a wrapper around the handle returned by the foreign code
182+
// Define a wrapper around the handle returned by the foreign code.
183+
// Unique<T> has the same semantics as ~T
183184
pub struct Unique<T> {
185+
// It contains a single raw, mutable pointer to the object in question.
184186
priv ptr: *mut T
185187
}
186188
189+
// Implement methods for creating and using the values in the box.
190+
// NB: For simplicity and correctness, we require that T has kind Send
191+
// (owned boxes relax this restriction, and can contain managed (GC) boxes).
192+
// This is because, as implemented, the garbage collector would not know
193+
// about any shared boxes stored in the malloc'd region of memory.
187194
impl<T: Send> Unique<T> {
188195
pub fn new(value: T) -> Unique<T> {
189196
unsafe {
190197
let ptr = malloc(std::mem::size_of::<T>() as size_t) as *mut T;
191198
assert!(!ptr::is_null(ptr));
192199
// `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
200+
// move_val_init moves a value into this memory without
201+
// attempting to drop the original value.
193202
intrinsics::move_val_init(&mut *ptr, value);
194203
Unique{ptr: ptr}
195204
}
@@ -206,12 +215,20 @@ impl<T: Send> Unique<T> {
206215
}
207216
}
208217
218+
// The key ingredient for safety, we associate a destructor with
219+
// Unique<T>, making the struct manage the raw pointer: when the
220+
// struct goes out of scope, it will automatically free the raw pointer.
221+
// NB: This is an unsafe destructor, because rustc will not normally
222+
// allow destructors to be associated with parametrized types, due to
223+
// bad interaction with managed boxes. (With the Send restriction,
224+
// we don't have this problem.)
209225
#[unsafe_destructor]
210226
impl<T: Send> Drop for Unique<T> {
211227
fn drop(&mut self) {
212228
unsafe {
213-
let x = intrinsics::init(); // dummy value to swap in
214-
// moving the object out is needed to call the destructor
229+
let x = intrinsics::uninit(); // dummy value to swap in
230+
// We need to move the object out of the box, so that
231+
// the destructor is called (at the end of this scope.)
215232
ptr::replace_ptr(self.ptr, x);
216233
free(self.ptr as *c_void)
217234
}

branches/try2/doc/tutorial-rustpkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Now you can install and use it! Go anywhere else in your filesystem:
198198

199199
~~~ {.notrust}
200200
$ cd ~/src/foo
201-
$ rustpkg install github/YOUR_USERNAME/hello
201+
$ rustpkg install github.com/YOUR_USERNAME/hello
202202
WARNING: The Rust package manager is experimental and may be unstable
203203
note: Installed package github.com/YOUR_USERNAME/hello-0.1 to /home/yourusername/src/hello/.rust
204204
~~~

0 commit comments

Comments
 (0)