From be1e100e38945418dfa1656741bccf9dc7674de9 Mon Sep 17 00:00:00 2001 From: zabackary <137591653+zabackary@users.noreply.github.com> Date: Mon, 22 Jul 2024 04:14:17 +0900 Subject: [PATCH] [rust/en] fix a typo and make some explanations clearer (#4998) --- rust.html.markdown | 14 +++++++++----- 1 file 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` and always hold a valid UTF-8 sequence, + // Stored as a `Vec` 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`. 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 { 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 { 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 = Box::new(3); *mine = 5; // dereference // Here, `now_its_mine` takes ownership of `mine`. In other words, `mine` is moved.