mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-18 11:26:27 +00:00
Fix formatting
This commit is contained in:
parent
dd447cfbcc
commit
613963b4df
1 changed files with 29 additions and 30 deletions
13
Rust/Rust.md
13
Rust/Rust.md
|
@ -51,7 +51,8 @@ io::stdin() // read line from stdin
|
|||
.expect("Error Message"); // in case of errors return an error message (io::Result) -- NEEDED
|
||||
```
|
||||
|
||||
The `::` syntax in the `::new` line indicates that `new` is an **associated function** of the `String` type. An associated function is implemented on a type rather than on a particular instance of the type. Some languages call this a `static method`.
|
||||
The `::` syntax in the `::new` line indicates that `new` is an **associated function** of the `String` type.
|
||||
An associated function is implemented on a type rather than on a particular instance of the type. Some languages call this a `static method`.
|
||||
|
||||
The `&` indicates that this argument is a reference, which gives a way to let multiple parts of the code access one piece of data without needing to copy that data into memory multiple times.
|
||||
|
||||
|
@ -74,7 +75,8 @@ const CONSTANT_NAME: type = value; // constant must have the type annotation
|
|||
It's possible declare a new variable with the *same name* as a previous variable, and the new variable *shadows* the previous variable.
|
||||
By using let, it's possible to perform a few transformations on a value but have the variable be immutable after those transformations have been completed.
|
||||
|
||||
The other difference between *mut* and *shadowing* is that because we’re effectively creating a new variable when we use the let keyword again, we can change the type of the value but reuse the same name.
|
||||
The other difference between *mut* and *shadowing* is that because we’re effectively creating a new variable when we use the let keyword again,
|
||||
we can change the type of the value but reuse the same name.
|
||||
|
||||
```rs
|
||||
let x: u32 = 10;
|
||||
|
@ -533,7 +535,8 @@ enum Option<T> {
|
|||
|
||||
### Match Expression + Comparing
|
||||
|
||||
A **match expression** is made up of *arms*. An arm consists of a *pattern* and the code that should be run if the value given to the beginning of the match expression fits that arm’s pattern.
|
||||
A **match expression** is made up of *arms*.
|
||||
An arm consists of a *pattern* and the code that should be run if the value given to the beginning of the match expression fits that arm’s pattern.
|
||||
Rust takes the value given to match and looks through each arm’s pattern in turn.
|
||||
|
||||
**NOTE**: `match` arms must be exaustive for compilation.
|
||||
|
@ -595,7 +598,3 @@ let v = vec![
|
|||
Enum::Text("TEST")
|
||||
];
|
||||
```
|
||||
|
||||
### String
|
||||
|
||||
### Hash Map
|
||||
|
|
Loading…
Add table
Reference in a new issue