Skip to content

Commit

Permalink
Merge pull request #91 from ferrous-systems/amanjeev/some-notes
Browse files Browse the repository at this point in the history
Moar notes!
  • Loading branch information
jonathanpallant authored Feb 1, 2024
2 parents 75b6b3b + f66e5b6 commit 46a145b
Show file tree
Hide file tree
Showing 2 changed files with 30 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
18 changes: 18 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 Expand Up @@ -156,6 +163,13 @@ fn main() {
}
```

Note:

* `IntoIterator` is actually dependent on the context. Depending on the context it will produce an iterator with owned elements, with references to elements, with mutable references to elements.
* e.g. `impl<T, A> IntoIterator for Vec<T, A>` for owned
* `impl<'a, T, A> IntoIterator for &'a Vec<T, A>` for refs
* `impl<'a, T, A> IntoIterator for &'a mut Vec<T, A>` for mut refs

## Things you can make iterators from

* [Ranges](https://doc.rust-lang.org/std/ops/struct.Range.html) (`0..10` or `0..=9`)
Expand Down Expand Up @@ -241,6 +255,10 @@ fn main() {
}
```

Note:

* Point out the type inference where Rust figures out `data` is an array of `u32` and not the default `i32`s.

## Call chaining (2)

What really happened:
Expand Down

0 comments on commit 46a145b

Please sign in to comment.