diff options
| author | zabackary <137591653+zabackary@users.noreply.github.com> | 2024-07-22 04:14:17 +0900 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-21 12:14:17 -0700 | 
| commit | be1e100e38945418dfa1656741bccf9dc7674de9 (patch) | |
| tree | f355c8e6a6680a804a3f3f033671821d3fa7e432 /rust.html.markdown | |
| parent | 08b303dab76f725f671ca3149f697961e0006d30 (diff) | |
[rust/en] fix a typo and make some explanations clearer (#4998)
Diffstat (limited to 'rust.html.markdown')
| -rw-r--r-- | rust.html.markdown | 14 | 
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. | 
