Skip to content

Commit 2309d41

Browse files
committed
Merge remote-tracking branch 'origin/main' into github-pages
2 parents a8583d1 + 9ddc43b commit 2309d41

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

content/en/docs/a8.primitive-data-types.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ let b: &str = "こんにちは, 世界!";
213213

214214
`&'static str` is an `&str` that is statically allocated directly to the read-only data segment in the program binary. The `'static` lifetime means it lives for the entire program duration.
215215

216-
> 💯 [`String`](https://doc.rust-lang.org/std/string/struct.String.html) type is a growable, heap-allocated, UTF-8 encoded string, which can be generated from a `&str` type, via [`to_string()`](https://doc.rust-lang.org/std/string/trait.ToString.html), [`to_owned()`](https://doc.rust-lang.org/std/borrow/trait.ToOwned.html) or [`String::from()`](https://doc.rust-lang.org/std/string/struct.String.html#method.from) methods. With [`as_str()`]() method, a `String` type can be converted to a `&str` type.
216+
> **💯 String**
217+
>
218+
> - 💡 String: capital "S" as [it's a struct](https://doc.rust-lang.org/std/string/struct.String.html#representation).
219+
> - [`String`](https://doc.rust-lang.org/std/string/struct.String.html) type is a growable, heap-allocated, UTF-8 encoded string. It is a sized type.
220+
> - String is the most common string type. In general, you should use `String` when you need [`ownership`](/docs/ownership), and `&str` when you just need to borrow a string.
221+
> - Can be generated from a `&str` type, via [`to_string()`](https://doc.rust-lang.org/std/string/trait.ToString.html), [`to_owned()`](https://doc.rust-lang.org/std/borrow/trait.ToOwned.html) or [`String::from()`](https://doc.rust-lang.org/std/string/struct.String.html#method.from) methods. With [`as_str()`](https://doc.rust-lang.org/std/string/struct.String.html#method.as_str) method, a `String` type can be converted to a `&str` type.
217222
>
218223
> ```rust
219224
> let s: &str = "Hello"; // &str
@@ -227,11 +232,6 @@ let b: &str = "こんにちは, 世界!";
227232
> let a = String::from("Hello"); // String
228233
> let b = a.as_str(); // &str
229234
> ```
230-
>
231-
> In the above examples, creating a `String` from a string slice (`&str` like `"Hello"`) via both `.to_string()` and `.to_owned()`
232-
> are functionally identical. Both call `String::from(self)` for `&str`.
233-
234-
💡 In general, you should use `String` when you need [`ownership`](/docs/ownership), and `&str` when you just need to borrow a string.
235235
236236
## Function
237237

content/en/docs/b1.vectors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ slug: vectors
55

66
If you remember, the array is a fixed-size list of elements, of the same data type. Even with mut, its element count cannot be changed. A vector is **kind of a re-sizable array** but **all elements must be in the same type**.
77

8-
⭐️ It’s a generic type, written as **`Vec<T>`** . T can have any type, ex. The type of a Vec of i32s is `Vec<i32>`. Also, Vectors always allocate their data in a dynamically allocated heap.
8+
> 💡 `Vec<T>`: capital “V” as [it’s a struct](https://doc.rust-lang.org/std/vec/struct.Vec.html).
9+
10+
It’s a generic type, written as **`Vec<T>`**. T can have any type, ex. A vector of i32s is `Vec<i32>`. Also, Vectors always allocate their data in a dynamically allocated heap.
911

1012
## Creation
1113

content/en/docs/b3.enums.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ fn main() {
6464
println!("{a:?}"); // Success
6565
println!("{b:?}"); // Error(401, "Unauthorized")
6666
println!("{c:?}"); // Warning { field: "email", message: "This is required" }
67+
68+
// 💡 Variable declaration and assignment, separately
69+
let a: FlashMessage; // Declaration with the type
70+
a = FlashMessage::Success; // Assignment with the value
71+
println!("{a:?}"); // Success
6772
}
6873
```
6974

0 commit comments

Comments
 (0)