summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--rust.html.markdown14
1 files changed, 9 insertions, 5 deletions
diff --git a/rust.html.markdown b/rust.html.markdown
index 11483eef..61754378 100644
--- a/rust.html.markdown
+++ b/rust.html.markdown
@@ -92,14 +92,14 @@ fn main() {
println!("{} {}", f, x); // 1.3 hello world
// A `String` – a heap-allocated string
- // Stored as a `Vec<u8>` and always hold a valid UTF-8 sequence,
+ // Stored as a `Vec<u8>` and always holds a valid UTF-8 sequence,
// which is not null terminated.
let s: String = "hello world".to_string();
// A string slice – an immutable view into another string
- // This is basically an immutable pair of pointers to a string – it doesn’t
- // actually contain the contents of a string, just a pointer to
- // the beginning and a pointer to the end of a string buffer,
+ // This is basically an immutable pointer and length of a string – it
+ // doesn’t actually contain the contents of a string, just a pointer to
+ // the beginning and a length of a string buffer,
// statically allocated or contained in another object (in this case, `s`).
// The string slice is like a view `&[u8]` into `Vec<T>`.
let s_slice: &str = &s;
@@ -162,6 +162,8 @@ fn main() {
let up = Direction::Up;
// Enum with fields
+ // If you want to make something optional, the standard
+ // library has `Option`
enum OptionalI32 {
AnI32(i32),
Nothing,
@@ -175,6 +177,8 @@ fn main() {
struct Foo<T> { bar: T }
// This is defined in the standard library as `Option`
+ // `Option` is used in place of where a null pointer
+ // would normally be used.
enum Optional<T> {
SomeVal(T),
NoVal,
@@ -304,7 +308,7 @@ fn main() {
/////////////////////////////////
// Owned pointer – only one thing can ‘own’ this pointer at a time
- // This means that when the `Box` leaves its scope, it can be automatically deallocated safely.
+ // This means that when the `Box` leaves its scope, it will be automatically deallocated safely.
let mut mine: Box<i32> = Box::new(3);
*mine = 5; // dereference
// Here, `now_its_mine` takes ownership of `mine`. In other words, `mine` is moved.