added link to Chinese translation rec#issuecomment-613319223 + minor cleanup of code in Pin chapter

This commit is contained in:
Carl Fredrik Samson
2020-04-14 23:05:54 +02:00
parent 2fc79a9e03
commit bd7e3c5572
8 changed files with 36 additions and 47 deletions

View File

@@ -60,9 +60,8 @@ struct Test {
impl Test {
fn new(txt: &str) -> Self {
let a = String::from(txt);
Test {
a,
a: String::from(txt),
b: std::ptr::null(),
}
}
@@ -291,10 +290,9 @@ impl Test {
fn new(txt: &str) -> Self {
let a = String::from(txt);
Test {
a,
a: String::from(txt),
b: std::ptr::null(),
// This makes our type `!Unpin`
_marker: PhantomPinned,
_marker: PhantomPinned, // This makes our type `!Unpin`
}
}
fn init<'a>(self: Pin<&'a mut Self>) {
@@ -404,12 +402,10 @@ pub fn main() {
#
# impl Test {
# fn new(txt: &str) -> Self {
# let a = String::from(txt);
# Test {
# a,
# a: let a = String::from(txt),
# b: std::ptr::null(),
# // This makes our type `!Unpin`
# _marker: PhantomPinned,
# _marker: PhantomPinned, // This makes our type `!Unpin`
# }
# }
# fn init<'a>(self: Pin<&'a mut Self>) {
@@ -465,12 +461,10 @@ us from swapping the pinned pointers.
> #
> # impl Test {
> # fn new(txt: &str) -> Self {
> # let a = String::from(txt);
> # Test {
> # a,
> # a: String::from(txt),
> # b: std::ptr::null(),
> # // This makes our type `!Unpin`
> # _marker: PhantomPinned,
> # _marker: PhantomPinned, // This makes our type `!Unpin`
> # }
> # }
> # fn init<'a>(self: Pin<&'a mut Self>) {
@@ -508,9 +502,8 @@ struct Test {
impl Test {
fn new(txt: &str) -> Pin<Box<Self>> {
let a = String::from(txt);
let t = Test {
a,
a: String::from(txt),
b: std::ptr::null(),
_marker: PhantomPinned,
};

View File

@@ -64,6 +64,10 @@ A special thanks to [jonhoo](https://twitter.com/jonhoo) who was kind enough to
give me some valuable feedback on a very early draft of this book. He has not
read the finished product, but a big thanks is definitely due.
## Translations
[This book has been translated to Chinese](https://stevenbai.top/rust/futures_explained_in_200_lines_of_rust/) by [nkbai](https://github.com/nkbai).
[mdbook]: https://github.com/rust-lang/mdBook
[book_repo]: https://github.com/cfsamson/books-futures-explained
[example_repo]: https://github.com/cfsamson/examples-futures