-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
582 additions
and
253 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Contributing | ||
|
||
## 🚧 Under construction! 🚧 | ||
|
||
Thanks for your interesting in helping us with this! At the moment, we are not | ||
ready for contributions, though. | ||
|
||
Once we stabilize the contents of the book, including the APIs we are | ||
re-exporting here and the little bits of functionality implemented in that | ||
crate, we will gladly take all the help we can get for maintaining this. We will | ||
update this document once we are ready for contributions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "trpl" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tokio = { version = "1", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# The Rust Programming Language Book Crate | ||
|
||
 | ||
|
||
This repository is the home of the `trpl` crate used in _The Rust Programming | ||
Language_ book materials. | ||
|
||
This crate mostly just re-exports items from *other* crates. It exists for two | ||
main reasons: | ||
|
||
1. So that as you read along in _The Rust Programming Language_, you can add | ||
just one dependency, rather than however many we end up with, and likewise | ||
use only one set of imports. | ||
|
||
2. So that we can more easily guarantee it keeps building and working. Since we | ||
control the contents of this crate and when it changes, readers will never be | ||
broken by upstream changes, e.g. if Tokio does a breaking 2.0 release at some | ||
point. | ||
|
||
## Requirements | ||
|
||
<!-- TODO: pick an appropriate starting version! --> | ||
This crate currently requires at least Rust 1.77. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//! A support crate for _The Rust Programming Language_. | ||
//! | ||
//! This crate mostly just re-exports items from *other* crates. It exists for | ||
//! two main reasons: | ||
//! | ||
//! 1. So that as you read along in _The Rust Programming Language_, you can | ||
//! add just one dependency, rather than however many we end up with, and | ||
//! likewise use only one set of imports. | ||
//! | ||
//! 2. So that we can more easily guarantee it keeps building and working. Since | ||
//! we control the contents of this crate and when it changes, readers will | ||
//! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 | ||
//! release at some point. | ||
pub use tokio::main as async_main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! Integration tests for the crate. | ||
//! | ||
//! These all live in a *single* integration test crate, `tests/integration`, | ||
//! because each integration test is a dedicated binary crate which has to be | ||
//! compiled separately. While that is not really a problem for a crate this | ||
//! small, we have chosen to follow this “best practice” here as a good example. | ||
//! | ||
//! For more details on why you might prefer this pattern see [this post][post]. | ||
//! | ||
//! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html | ||
use trpl::async_main; | ||
|
||
/// This test makes sure the re-exported version of the `tokio::main` macro, | ||
/// which is applied like `#[tokio::main] async fn some_fn() { … }`, continues | ||
/// to work. However, tests cannot use `async fn`, so to test it, we need to | ||
/// have a non-`async` test function, which then applies the macro to an `async` | ||
/// function in its body, and invokes *that*. | ||
#[test] | ||
fn re_exported_macro_works() { | ||
#[async_main] | ||
async fn internal() -> &'static str { | ||
let val = async { "Hello" }.await; | ||
assert_eq!(val, "Hello", "Async is usable in async_main function"); | ||
val | ||
} | ||
|
||
assert_eq!(internal(), "Hello", "value returns correctly"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.