From 3474b1b1ca5152d6f1b16f3937b8e42ed3fbcb5d Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Mon, 21 Aug 2023 11:21:39 -0400 Subject: [PATCH 1/2] iterators: notes --- training-slides/src/iterators.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/training-slides/src/iterators.md b/training-slides/src/iterators.md index 8f539c2e..56cad17a 100644 --- a/training-slides/src/iterators.md +++ b/training-slides/src/iterators.md @@ -156,6 +156,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 IntoIterator for Vec` for owned +* `impl<'a, T, A> IntoIterator for &'a Vec` for refs +* `impl<'a, T, A> IntoIterator for &'a mut Vec` 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`) @@ -241,6 +248,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: From f66e5b63be2c09b4477a8b976ca23c8a33c71ae3 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Wed, 23 Aug 2023 10:25:46 -0400 Subject: [PATCH 2/2] add notes: iterators, io, --- training-slides/src/io.md | 12 ++++++++++++ training-slides/src/iterators.md | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/training-slides/src/io.md b/training-slides/src/io.md index de536309..307dfd78 100644 --- a/training-slides/src/io.md +++ b/training-slides/src/io.md @@ -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 @@ -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 diff --git a/training-slides/src/iterators.md b/training-slides/src/iterators.md index 56cad17a..a5aff7f6 100644 --- a/training-slides/src/iterators.md +++ b/training-slides/src/iterators.md @@ -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 where T: Iterator { inner: T }` +* `struct SomeOtherIter { random_seed: u32 }` + ## Important to note * Iterators are lazy