Skip to content

Commit 0d8c5ac

Browse files
committed
added readme
1 parent 4e6d773 commit 0d8c5ac

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
1-
# Asynchronous-Programming-in-Rust
1+
# Asynchronous Programming in Rust
2+
3+
This is the repository for the book: Asynchronous Programming in Rust - learn asynchronous programming from first principles.
4+
5+
Written by Carl Fredrik Samson, published by Packt
6+
7+
## How to use this repository
8+
9+
My clear recommendation is to clone this repository by either click on the `<> Code` button and select "Download ZIP" or clone the repository using your preferred git client.
10+
11+
Each chapter has its own folder in this repository. Each example is organized as a standalone crate within that folder.
12+
13+
When encountering examples in the book, you might find it easier to read in the repository since you'll be able to open it up in the editor of your choice with approperiate highlighting and formatting.
14+
15+
Even if you prefer to write the examples from the book line by line, you'll need the repository for `delayserver` and `corofy` which is two tools I wrote to help in the learning process.
16+
17+
## Delayserver
18+
19+
Most of the examples will use a program called delayserver that's provided in this repository. Delayserver is a simple local webserver where you can write a HTTP GET request with a configurable delay.
20+
21+
You have two options for running the delayserver:
22+
23+
1. Go to the folder called delayserver and write `cargo run` in a separate terminal window and leave it running there
24+
2. Go to the delayserver and install the server by writing `cargo install --force --path .`. By doing so you install the program locally in you PATH so you can run it from any location by simply writing `delayserver` and leave the terminal process running.
25+
26+
## Corofy
27+
28+
Corofy is another tool that we'll use from chapter 7 onwards. I recommend installing this tool by entering the folder `ch7/corofy` and installing it on your machine by writing `cargo install --force --path .`
29+
30+
## I'll be going on a plane, how can I use the repository in an offline situation?
31+
32+
You'll need to install both delayserver and corofy locally on your machine wile you're online.
33+
34+
Most of the examples has no external dependencies, but from chapter 6 onwards
35+
we will have one or more external dependencies. The best way to be able to run these examples while offline is to enter each folder and use [cargo vendor](https://doc.rust-lang.org/cargo/commands/cargo-vendor.html) to vendor the dependencies locally. This way you'll be able to build and experiment with the examples even though you'll be offline.
36+
37+
238
Asynchronous Programming in Rust, published by Packt

ch04/a-epoll/src/poll.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::{io::{self, Result}, net::TcpStream, os::fd::AsRawFd};
1+
use std::{
2+
io::{self, Result},
3+
net::TcpStream,
4+
os::fd::AsRawFd,
5+
};
26

37
use crate::ffi;
48

@@ -47,13 +51,11 @@ impl Poll {
4751
}
4852
}
4953

50-
5154
pub struct Registry {
5255
raw_fd: i32,
5356
}
5457

5558
impl Registry {
56-
5759
// NB! Mio inverts this, and `source` owns the register implementation
5860
pub fn register(&self, source: &TcpStream, token: usize, interests: i32) -> Result<()> {
5961
let mut event = ffi::Event {
@@ -62,9 +64,7 @@ impl Registry {
6264
};
6365

6466
let op = ffi::EPOLL_CTL_ADD;
65-
let res = unsafe {
66-
ffi::epoll_ctl(self.raw_fd, op, source.as_raw_fd(), &mut event)
67-
};
67+
let res = unsafe { ffi::epoll_ctl(self.raw_fd, op, source.as_raw_fd(), &mut event) };
6868

6969
if res < 0 {
7070
return Err(io::Error::last_os_error());
@@ -83,4 +83,4 @@ impl Drop for Registry {
8383
println!("ERROR: {err:?}");
8484
}
8585
}
86-
}
86+
}

0 commit comments

Comments
 (0)