Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

annually update from upstream #92

Merged
merged 30 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9b936d4
Add time::Duration import to snippet
d2weber Jul 24, 2022
919f1c2
Use install-action to install mdbook and mdbook-linkcheck
taiki-e Jul 30, 2022
e409a5c
Migrate to Rust 2021
taiki-e Jul 30, 2022
1fb57ec
Add missing html files
taiki-e Jul 30, 2022
a7974c8
Unify import style
taiki-e Jul 30, 2022
81c03c2
Remove unnecessary code from example
emhane Mar 10, 2022
273aa2d
07 workarounds/async in trait: update that nightly has mvp
harryhaaren Dec 12, 2022
e224ead
Merge pull request #180 from harryhaaren/async_in_trait_update
eholk Dec 22, 2022
4ae6ecf
Add new translation
rouzbehsbz Jan 6, 2023
70ef3c1
Add details of the compiler errors that occur when trying to use get_…
hydra Feb 1, 2023
6957e04
Added Spawning example
Nereuxofficial Feb 2, 2023
0f396af
Removed test for local testing
Nereuxofficial Feb 2, 2023
24861ba
Reworded a sentence
Nereuxofficial Feb 2, 2023
d9f4e06
Added `` around function
Nereuxofficial Feb 2, 2023
3889ec8
JoinHandle now in Codeblock and added note about channels
Nereuxofficial Feb 2, 2023
330d3a4
Added JoinHandle to dictionary
Nereuxofficial Feb 2, 2023
cc31e99
Fixed Sentence about channels
Nereuxofficial Feb 3, 2023
c618588
Updated async dependency
Nereuxofficial Feb 3, 2023
6360806
Merge pull request #192 from Nereuxofficial/updated-dependencies
eholk Feb 3, 2023
bac6958
Remove unecessary pointer dereferencing
brunojppb Feb 12, 2023
fc9038c
Obviously old comment removal
deep-outcome Feb 13, 2023
f4074ae
Merge pull request #193 from brunojppb/fix-remove-dereferencing
eholk Mar 29, 2023
41023fb
Merge pull request #194 from bravequickcleverfibreyarn/6_3_select_exa…
eholk Mar 30, 2023
9c30051
Merge pull request #190 from hydra/add-pinning-compilation-error-details
eholk Mar 30, 2023
87ac3cb
Merge branch 'rust-lang:master' into spawning
Nereuxofficial May 5, 2023
d4d7505
Review Fixes. Thanks to @eholk
Nereuxofficial May 5, 2023
04e8b6c
Added to dictionary
Nereuxofficial May 5, 2023
cdb9148
Merge pull request #185 from rouzbehsbz/fa-IR
eholk Jul 6, 2023
1ef20c7
Merge pull request #191 from Nereuxofficial/spawning
eholk Jul 6, 2023
ed022fc
Capitalize the first letter in the Pinning chapter
yuk1ty Oct 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ on:
jobs:
test:
name: build and test
env:
MDBOOK_LINKCHECK_VERSION: 0.7.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable && rustup default stable
- run: sudo apt-get update && sudo apt-get install aspell aspell-en
- name: Install mdbook and mdbook-linkcheck
run: |
tag=$(curl -LsSf https://api.github.com/repos/rust-lang/mdBook/releases/latest | jq -r '.tag_name')
curl -LsSf https://github.com/rust-lang/mdBook/releases/download/$tag/mdbook-$tag-x86_64-unknown-linux-gnu.tar.gz | tar xzf -
curl -LsSf https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/v${MDBOOK_LINKCHECK_VERSION}/mdbook-linkcheck-v${MDBOOK_LINKCHECK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar xzf -
echo $(pwd) >> $GITHUB_PATH
- name: Install mdbook
uses: taiki-e/install-action@mdbook
- name: Install mdbook-linkcheck
uses: taiki-e/install-action@mdbook-linkcheck
- run: bash ci/spellcheck.sh list
- run: mdbook build
- run: cargo test --all --manifest-path=./examples/Cargo.toml --target-dir ./target
Expand Down
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://github.com/rust-lang/async-book/pull/59#issuecomment-556240879
disable_all_formatting = true
2 changes: 2 additions & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AsyncRead
AsyncWrite
AwaitingFutOne
AwaitingFutTwo
cancelling
combinator
combinators
compat
Expand Down Expand Up @@ -37,6 +38,7 @@ interprocess
IoBlocker
IOCP
IoObject
JoinHandle
kqueue
localhost
LocalExecutor
Expand Down
2 changes: 1 addition & 1 deletion examples/01_02_why_async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_01_02_why_async"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
9 changes: 2 additions & 7 deletions examples/01_02_why_async/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#![cfg(test)]

use {
futures::{
executor::block_on,
join,
},
std::thread,
};
use futures::{executor::block_on, join};
use std::thread;

fn download(_url: &str) {
// ...
Expand Down
2 changes: 1 addition & 1 deletion examples/01_04_async_await_primer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_01_04_async_await_primer"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion examples/02_02_future_trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
name = "example_02_02_future_trait"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]
2 changes: 1 addition & 1 deletion examples/02_03_timer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_02_03_timer"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion examples/02_04_executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_02_04_executor"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
28 changes: 13 additions & 15 deletions examples/02_04_executor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#![cfg(test)]

// ANCHOR: imports
use {
futures::{
future::{BoxFuture, FutureExt},
task::{waker_ref, ArcWake},
},
std::{
future::Future,
sync::mpsc::{sync_channel, Receiver, SyncSender},
sync::{Arc, Mutex},
task::Context,
time::Duration,
},
// The timer we wrote in the previous section:
timer_future::TimerFuture,
use futures::{
future::{BoxFuture, FutureExt},
task::{waker_ref, ArcWake},
};
use std::{
future::Future,
sync::mpsc::{sync_channel, Receiver, SyncSender},
sync::{Arc, Mutex},
task::Context,
time::Duration,
};
// The timer we wrote in the previous section:
use timer_future::TimerFuture;
// ANCHOR_END: imports

// ANCHOR: executor_decl
Expand Down Expand Up @@ -92,7 +90,7 @@ impl Executor {
if let Some(mut future) = future_slot.take() {
// Create a `LocalWaker` from the task itself
let waker = waker_ref(&task);
let context = &mut Context::from_waker(&*waker);
let context = &mut Context::from_waker(&waker);
// `BoxFuture<T>` is a type alias for
// `Pin<Box<dyn Future<Output = T> + Send + 'static>>`.
// We can get a `Pin<&mut dyn Future + Send + 'static>`
Expand Down
2 changes: 1 addition & 1 deletion examples/03_01_async_await/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_03_01_async_await"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion examples/05_01_streams/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_05_01_streams"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
18 changes: 7 additions & 11 deletions examples/05_01_streams/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![cfg(test)]

mod stream_trait {
use {
futures::stream::{Stream as RealStream},
std::{
pin::Pin,
task::{Context, Poll},
},
use futures::stream::Stream as RealStream;
use std::{
pin::Pin,
task::{Context, Poll},
};

// ANCHOR: stream_trait
Expand Down Expand Up @@ -34,11 +32,9 @@ impl<I> Stream for dyn RealStream<Item = I> {
}

mod channels {
use {
futures::{
channel::mpsc,
prelude::*,
},
use futures::{
channel::mpsc,
prelude::*,
};

// ANCHOR: channels
Expand Down
2 changes: 1 addition & 1 deletion examples/05_02_iteration_and_concurrency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_05_02_iteration_and_concurrency"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
16 changes: 7 additions & 9 deletions examples/05_02_iteration_and_concurrency/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#![cfg(test)]

use {
futures::{
executor::block_on,
stream::{self, Stream},
},
std::{
io,
pin::Pin,
},
use futures::{
executor::block_on,
stream::{self, Stream},
};
use std::{
io,
pin::Pin,
};

// ANCHOR: nexts
Expand Down
2 changes: 1 addition & 1 deletion examples/06_02_join/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_06_02_join"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion examples/06_03_select/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_06_03_select"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
7 changes: 0 additions & 7 deletions examples/06_03_select/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,6 @@ async fn get_new_num() -> u8 { /* ... */ 5 }

async fn run_on_new_num(_: u8) -> u8 { /* ... */ 5 }

// Runs `run_on_new_num` with the latest number
// retrieved from `get_new_num`.
//
// `get_new_num` is re-run every time a timer elapses,
// immediately cancelling the currently running
// `run_on_new_num` and replacing it with the newly
// returned value.
async fn run_loop(
mut interval_timer: impl Stream<Item = ()> + FusedStream + Unpin,
starting_num: u8,
Expand Down
13 changes: 13 additions & 0 deletions examples/06_04_spawning/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "example_06_04_spawning"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3"

[dependencies.async-std]
version = "1.12.0"
features = ["attributes"]
46 changes: 46 additions & 0 deletions examples/06_04_spawning/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#![cfg(test)]
#![allow(dead_code)]

// ANCHOR: example
use async_std::{task, net::TcpListener, net::TcpStream};
use futures::AsyncWriteExt;

async fn process_request(stream: &mut TcpStream) -> Result<(), std::io::Error>{
stream.write_all(b"HTTP/1.1 200 OK\r\n\r\n").await?;
stream.write_all(b"Hello World").await?;
Ok(())
}

async fn main() {
let listener = TcpListener::bind("127.0.0.1:8080").await.unwrap();
loop {
// Accept a new connection
let (mut stream, _) = listener.accept().await.unwrap();
// Now process this request without blocking the main loop
task::spawn(async move {process_request(&mut stream).await});
}
}
// ANCHOR_END: example
use std::time::Duration;
async fn my_task(time: Duration) {
println!("Hello from my_task with time {:?}", time);
task::sleep(time).await;
println!("Goodbye from my_task with time {:?}", time);
}
// ANCHOR: join_all
use futures::future::join_all;
async fn task_spawner(){
let tasks = vec![
task::spawn(my_task(Duration::from_secs(1))),
task::spawn(my_task(Duration::from_secs(2))),
task::spawn(my_task(Duration::from_secs(3))),
];
// If we do not await these tasks and the function finishes, they will be dropped
join_all(tasks).await;
}
// ANCHOR_END: join_all

#[test]
fn run_task_spawner() {
futures::executor::block_on(task_spawner());
}
2 changes: 1 addition & 1 deletion examples/07_05_recursion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "example_07_05_recursion"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion examples/09_01_sync_tcp_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "sync_tcp_server"
version = "0.1.0"
authors = ["Your Name <[email protected]"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
4 changes: 2 additions & 2 deletions examples/09_02_async_tcp_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
name = "async_tcp_server"
version = "0.1.0"
authors = ["Your Name <[email protected]"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.async-std]
version = "1.6"
version = "1.12"
features = ["attributes"]
11 changes: 11 additions & 0 deletions examples/09_03_slow_request/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello!</title>
</head>
<body>
<h1>Oops!</h1>
<p>Sorry, I don't know what you're asking for.</p>
</body>
</html>
4 changes: 2 additions & 2 deletions examples/09_03_slow_request/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
name = "slow_request"
version = "0.1.0"
authors = ["Your Name <[email protected]"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.async-std]
version = "1.6"
version = "1.12"
features = ["attributes"]
11 changes: 11 additions & 0 deletions examples/09_03_slow_request/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello!</title>
</head>
<body>
<h1>Hello!</h1>
<p>Hi from Rust</p>
</body>
</html>
Loading
Loading