Skip to content

Commit

Permalink
add notes: iterators, io,
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeev committed Aug 23, 2023
1 parent 6e6ce84 commit f66e5b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions training-slides/src/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ fn main() -> std::io::Result<()> {
* When do you hit the end of a `TcpStream`?
* When either side does a `shutdown`

Note:

* `Read` trait has a method `read_to_end()`

## Binding Ports

* `TcpListener` needs to know which IP address and port to bind
Expand All @@ -156,6 +160,14 @@ fn main() -> Result<(), std::io::Error> {
* [`SocketAddr`](https://doc.rust-lang.org/std/net/enum.SocketAddr.html) is an enum of [`SocketAddrV4`](https://doc.rust-lang.org/std/net/struct.SocketAddrV4.html) and [`SocketAddrV6`](https://doc.rust-lang.org/std/net/struct.SocketAddrV6.html)
* But TLS, HTTP and QUIC are all third-party crates

Note:

Some current prominent examples of each -

* TLS - [RusTLS](https://github.com/rustls/rustls)
* HTTP - [hyperium/http](https://github.com/hyperium/http)
* QUIC - [cloudflare/quiche](https://github.com/cloudflare/quiche)

## Failures

* Almost any I/O operation can fail
Expand Down
7 changes: 7 additions & 0 deletions training-slides/src/iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ To *iterate* in Rust is to produce a sequence of items, one at a time.
* Some *Iterators* will calculate each item on-the-fly
* Some *Iterators* will take data another iterator, and then calculate something new

Note:

Technically, all iterators calculate things on-the-fly. Some own another iterator and use that as input to their calculation, and some have an internal state that they can use for calculation. `fn next(&mut self) -> Self::Item` can only access `Self` so it is about what `Self` contains.

* `struct SomeIter<T> where T: Iterator { inner: T }`
* `struct SomeOtherIter { random_seed: u32 }`

## Important to note

* Iterators are lazy
Expand Down

0 comments on commit f66e5b6

Please sign in to comment.