Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested content #155

Closed
CasperN opened this issue Jan 11, 2023 · 0 comments
Closed

Suggested content #155

CasperN opened this issue Jan 11, 2023 · 0 comments

Comments

@CasperN
Copy link

CasperN commented Jan 11, 2023

Hi, here's some suggested content based on my experience teaching the course

  1. I think modules are not very interesting can be pushed to the last day. If we assume the audience can program in some other language, then the rest of the day 2 content (control flow and syntax) can be squeezed to the day 1 afternoon. That means the audience has to wait until the second day to see the famous borrow checker and talk about memory management but that can just be more motivation to show up :)

  2. An exercise that forces people to use pattern matching, result types, option types, and the ? operator (ideally all at once), but only using Copy types. This will let people see these important APIs and learn some pattern matching syntax before running into the borrow checker. Ideally this will force people to read the docs about methods on Options and Results since these types show up everywhere.

    • you do have to have #[derive(Copy)] and generics like Option<Foo> around but instructors can give a very brief hand-waved explanation for what those are
  3. Designing the HashMap API: There's a lot to say about it wrt generics, trait bounds, and associated types.

    • Many methods have the bounds, K: Borrow<Q> and Q: Hash + Eq + ?Sized, this is a good example of putting trait bounds on associated types
    • The entry API is somewhat unique to Rust and is pretty cool that it lets users avoid a lookup
    • This could be a good intro to generics
    • maybe talk about ?sized types too
  4. Implementing an Iterator: Here's a contrived example that will let you talk about lifetimes, the index trait, and the impl trait syntax.

/// Given some text, index all the sentences so you can access the Nth sentence in O(1) time.
struct SentenceIndex<'text> {
  text: &'text str,
  sentence_starts: Vec<usize>,
}
impl<'text> std::ops::Index<usize> for SentenceIndex<'text> {
  type Output: &'text str;
  // Note that &self has a different lifetime than &'text
  // The returned sentence str can outlive the SentenceIndex but not the underlying text.
  fn index(&self, i: usize) -> &'text str; 
}
impl<'text> SentenceIndex<'text> {
  fn iter(&self) -> impl Iterator<&'text str>;
}
@google google locked and limited conversation to collaborators Jan 11, 2023
@mgeisler mgeisler converted this issue into discussion #156 Jan 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant