Skip to content

Instantly share code, notes, and snippets.

@theangryangel
Created August 20, 2024 11:13
Show Gist options
  • Save theangryangel/7f5a62e13a1fd7a728149244dadf2c97 to your computer and use it in GitHub Desktop.
Save theangryangel/7f5a62e13a1fd7a728149244dadf2c97 to your computer and use it in GitHub Desktop.
mod thing {
pub(super) struct Thing {
pub(super) name: String,
pub(super) indicator: usize,
}
// ---8<--- ... impl Thing here
static THANGS: [Thing; 3] = [
Thing::new(1, 'Thing 1'),
Thing::new(2, 'Thing 2'),
Thing::new(3, 'Thing 3'),
];
pub(super) fn get(c: usize) -> Option<&'static Thing> {
THANGS.iter().find(|&r| r.indicator == c)
}
pub(super) fn iter() -> impl Iterator<Item = &'static Thing> {
THANGS.iter()
}
// etc..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment