Skip to content

Commit

Permalink
sprinkle inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jan 16, 2024
1 parent fb45db9 commit a4de3cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions prototypes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ where
}
}

#[inline]
pub fn try_prototype<ID: PrototypeID>(id: ID) -> Option<&'static <ID as PrototypeID>::Prototype>
where
ID::Prototype: ConcretePrototype,
{
<ID as PrototypeID>::Prototype::storage(try_prototypes()?).get(&id)
}

#[inline]
pub fn prototypes_iter<T: ConcretePrototype>() -> impl Iterator<Item = &'static T> {
let p = prototypes();
let storage = T::storage(p);
T::ordering(p).iter().map(move |id| &storage[id])
}

#[inline]
pub fn prototypes_iter_ids<T: ConcretePrototype>() -> impl Iterator<Item = T::ID> {
T::ordering(prototypes()).iter().copied()
}
Expand Down
2 changes: 2 additions & 0 deletions prototypes/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ macro_rules! gen_prototypes {
}

impl $t {
#[inline]
pub fn iter() -> impl Iterator<Item = &'static Self> {
$crate::prototypes_iter::<Self>()
}
#[inline]
pub fn iter_ids() -> impl Iterator<Item = $id> {
$crate::prototypes_iter_ids::<Self>()
}
Expand Down

0 comments on commit a4de3cf

Please sign in to comment.