Skip to content
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

GUI Exercise is more about text formatting than trait objects #1617

Closed
djmitche opened this issue Dec 27, 2023 · 4 comments · Fixed by #1682
Closed

GUI Exercise is more about text formatting than trait objects #1617

djmitche opened this issue Dec 27, 2023 · 4 comments · Fixed by #1682

Comments

@djmitche
Copy link
Collaborator

This is from feedback in #1565. It is in the "Methods and Traits" segment, so it doesn't necessarily need to focus on trait objects. But, something nifty with traits would be good.

I've not come up with a great idea yet. The best I've got is some kind of signal-processing DAG, like old-school analog synthesizers. So you'd have a few types that take dyn SignalSource trait objects, and themselves implement SignalSource. But, signal processing is a little complex for an example!

I'm open to ideas here!

@mgeisler
Copy link
Collaborator

mgeisler commented Jan 5, 2024

GUI Exercise is more about text formatting than trait objects

I agree... even though I love making this kind of formatting myself, it's not the right focus for this exercise.

@djmitche
Copy link
Collaborator Author

Per #1516, this is a little too early for trait objects anyway, so let's think of something that just requires traits.

@djmitche
Copy link
Collaborator Author

I think the simplest will be something where generics are used to support dependency injection. Something like

pub trait Storage {
    fn put(&mut self, k: String, v: String);
    fn get(&self, k: &str) -> Option<&str>;
}

pub struct InMemoryStorage;

impl Storage for InMemoryStorage { .. }

pub struct OnDiskStorage;

impl Storage for OnDiskstorage { .. }

fn uses_storage<S: Storage>(storage: S) {
  storage.put(..);
  // ...
}

@djmitche
Copy link
Collaborator Author

Unfortunately, the modules segment depends on this one, suggesting breaking it up into modules. Maybe that's OK? Maybe the exercise for that segment is "here's some code you haven't seen before, put it into modules" instead of "here's some code you worked on yesterday, .."? Being able to read Rust code is a good skill to practice, and that's probably a good segment to practice it in..

djmitche added a commit that referenced this issue Jan 18, 2024
This should be a bit simpler, and notably
* does not require trait objects, which per #1516 should be moved later
in the course
 * does not require a lot of futzing with string formatting

But all that hard work developing the GUI exercise is not for naught: it
remains in the "Modules" segment, where students will get a chance to
read some Rust code and reorganize it a little bit.

Fixes #1617.

R=mgeisler as the original author of the GUI exercise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants