Skip to content

Commit

Permalink
doc: Update with changes in field privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Mar 31, 2014
1 parent 8093427 commit 37a3131
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ use std::ptr;
// Unique<T> has the same semantics as ~T
pub struct Unique<T> {
// It contains a single raw, mutable pointer to the object in question.
priv ptr: *mut T
ptr: *mut T
}
// Implement methods for creating and using the values in the box.
Expand Down
15 changes: 6 additions & 9 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1527,12 +1527,9 @@ of an item to see whether it should be allowed or not. This is where privacy
warnings are generated, or otherwise "you used a private item of another module
and weren't allowed to."

By default, everything in rust is *private*, with two exceptions. The first
exception is that struct fields are public by default (but the struct itself is
still private by default), and the remaining exception is that enum variants in
a `pub` enum are the default visibility of the enum container itself.. You are
allowed to alter this default visibility with the `pub` keyword (or `priv`
keyword for struct fields and enum variants). When an item is declared as `pub`,
By default, everything in rust is *private*, with one exception. Enum variants
in a `pub` enum are also public by default. You are allowed to alter this
default visibility with the `priv` keyword. When an item is declared as `pub`,
it can be thought of as being accessible to the outside world. For example:

~~~~
Expand All @@ -1542,7 +1539,7 @@ struct Foo;
// Declare a public struct with a private field
pub struct Bar {
priv field: int
field: int
}
// Declare a public enum with public and private variants
Expand Down Expand Up @@ -2354,7 +2351,7 @@ The following are examples of structure expressions:
~~~~
# struct Point { x: f64, y: f64 }
# struct TuplePoint(f64, f64);
# mod game { pub struct User<'a> { name: &'a str, age: uint, score: uint } }
# mod game { pub struct User<'a> { pub name: &'a str, pub age: uint, pub score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10.0, y: 20.0};
TuplePoint(10.0, 20.0);
Expand Down Expand Up @@ -3140,7 +3137,7 @@ The types `char` and `str` hold textual data.
A value of type `char` is a [Unicode scalar value](
http://www.unicode.org/glossary/#unicode_scalar_value)
(ie. a code point that is not a surrogate),
represented as a 32-bit unsigned word in the 0x0000 to 0xD7FF
represented as a 32-bit unsigned word in the 0x0000 to 0xD7FF
or 0xE000 to 0x10FFFF range.
A `[char]` vector is effectively an UCS-4 / UTF-32 string.

Expand Down
8 changes: 4 additions & 4 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2657,8 +2657,8 @@ Rust doesn't support encapsulation: both struct fields and methods can
be private. But this encapsulation is at the module level, not the
struct level.

For convenience, fields are _public_ by default, and can be made _private_ with
the `priv` keyword:
Fields are _private_ by default, and can be made _public_ with
the `pub` keyword:

~~~
mod farm {
Expand All @@ -2667,8 +2667,8 @@ mod farm {
# impl Human { pub fn rest(&self) { } }
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], farmer: Human(0) } }
pub struct Farm {
priv chickens: ~[Chicken],
farmer: Human
chickens: ~[Chicken],
pub farmer: Human
}
impl Farm {
Expand Down

1 comment on commit 37a3131

@alexcrichton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=brson

Please sign in to comment.