add skeleton

This commit is contained in:
孙飞 2022-02-11 14:42:25 +08:00
parent aa691f9410
commit bef6354109
5 changed files with 75 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
book

20
book.toml Normal file
View File

@ -0,0 +1,20 @@
[book]
title = "Rust Exercise"
description = "A set of exercises and examples to pratice various aspects of Rust, also for the rust course (book) at https://course.rs"
authors = ["course.rs"]
language = "en"
multilingual = false
src = "src"
[output.html.playpen]
editable = true
editor = "ace"
[output.html.fold]
enable = true
[output.html]
git-repository-url = "https://github.com/course-rs/rust-exercise"
[rust]
edition = "2021"

4
src/SUMMARY.md Normal file
View File

@ -0,0 +1,4 @@
# Summary
- [Lifetime](lifetime/intro.md)
- [&'static and T: 'static](lifetime/static.md)

1
src/lifetime/intro.md Normal file
View File

@ -0,0 +1 @@
# Lifetime

49
src/lifetime/static.md Normal file
View File

@ -0,0 +1,49 @@
# &'static and T: 'static
```rust,editable
use std::fmt::Display;
fn main() {
let mut string = "First".to_owned();
string.push_str(string.to_uppercase().as_str());
print_a(&string);
print_b(&string);
print_c(&string); // Compilation error
print_d(&string); // Compilation error
print_e(&string);
print_f(&string);
print_g(&string); // Compilation error
}
fn print_a<T: Display + 'static>(t: &T) {
println!("{}", t);
}
fn print_b<T>(t: &T)
where
T: Display + 'static,
{
println!("{}", t);
}
fn print_c(t: &'static dyn Display) {
println!("{}", t)
}
fn print_d(t: &'static impl Display) {
println!("{}", t)
}
fn print_e(t: &(dyn Display + 'static)) {
println!("{}", t)
}
fn print_f(t: &(impl Display + 'static)) {
println!("{}", t)
}
fn print_g(t: &'static String) {
println!("{}", t);
}
```