mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 04:29:41 +00:00
Merge branch 'master' into edit
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
### Char
|
||||
1. 🌟
|
||||
```rust, editable
|
||||
```rust,editable
|
||||
|
||||
// Make it work
|
||||
use std::mem::size_of_val;
|
||||
@ -18,7 +18,7 @@ fn main() {
|
||||
```
|
||||
|
||||
2. 🌟
|
||||
```rust, editable
|
||||
```rust,editable
|
||||
|
||||
// Make it work
|
||||
fn main() {
|
||||
@ -33,7 +33,7 @@ fn print_char(c : char) {
|
||||
|
||||
### Bool
|
||||
3. 🌟
|
||||
```rust, editable
|
||||
```rust,editable
|
||||
|
||||
// Make println! work
|
||||
fn main() {
|
||||
@ -47,7 +47,7 @@ fn main() {
|
||||
```
|
||||
|
||||
4. 🌟
|
||||
```rust, editable
|
||||
```rust,editable
|
||||
|
||||
// Make it work
|
||||
fn main() {
|
||||
|
@ -24,7 +24,7 @@ fn main() {
|
||||
2. 🌟
|
||||
```rust,editable
|
||||
|
||||
// Fill the blank
|
||||
// Fill the blank
|
||||
fn main() {
|
||||
let v: u16 = 38_u8 as __;
|
||||
|
||||
|
@ -240,7 +240,7 @@ Besides jump into the standard library, you can also jump to another module in t
|
||||
// in lib.rs
|
||||
|
||||
mod a {
|
||||
/// Add four to the given value and return a [`Option`] type
|
||||
/// Add four to the given value and return a [`Option`] type
|
||||
/// [`crate::MySpecialFormatter`]
|
||||
pub fn add_four(x: i32) -> Option<i32> {
|
||||
Some(x + 4)
|
||||
|
@ -335,7 +335,7 @@ The `impl Trait` syntax works for straightforward cases but is actually syntax s
|
||||
When working with generics, the type parameters often must use traits as bounds to stipulate what functionality a type implements.
|
||||
|
||||
7. 🌟🌟
|
||||
```rust, editable
|
||||
```rust,editable
|
||||
fn main() {
|
||||
assert_eq!(sum(1, 2), 3);
|
||||
}
|
||||
|
@ -108,7 +108,9 @@ fn main() {
|
||||
## T: 'static
|
||||
As a trait bound, it means the type does not contain any non-static references. Eg. the receiver can hold on to the type for as long as they want and it will never become invalid until they drop it.
|
||||
|
||||
It's important to understand this means that any owned data always passes a `'static `lifetime bound, but a reference to that owned data generally does no.
|
||||
|
||||
It's important to understand this means that any owned data always passes a `'static `lifetime bound, but a reference to that owned data generally does not.
|
||||
|
||||
|
||||
5,🌟🌟
|
||||
```rust,editable
|
||||
@ -192,4 +194,4 @@ fn print_f(t: &(impl Display + 'static)) {
|
||||
fn print_g(t: &'static String) {
|
||||
println!("{}", t);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -62,7 +62,7 @@ fn print_str(s: String) {
|
||||
```
|
||||
|
||||
5. 🌟🌟
|
||||
```rust, editable
|
||||
```rust,editable
|
||||
// Don't use clone ,use copy instead
|
||||
fn main() {
|
||||
let x = (1, 2, (), "hello".to_string());
|
||||
|
@ -204,7 +204,7 @@ fn main() {
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it
|
@ -114,6 +114,6 @@ fn main() {
|
||||
&mut value => value.push_str(" world!")
|
||||
}
|
||||
}
|
||||
````
|
||||
```
|
||||
|
||||
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it
|
||||
|
Reference in New Issue
Block a user