Skip to content

Commit

Permalink
Merge pull request #712 from Imberflur/maybe-with
Browse files Browse the repository at this point in the history
Add `Builder::maybe_with` for convenient optional addition of a compo…
  • Loading branch information
zesterer authored Nov 21, 2020
2 parents 6cba11b + 1a2b6c7 commit 1fd81cd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,40 @@ pub trait Builder {
#[cfg(not(feature = "parallel"))]
fn with<C: Component>(self, c: C) -> Self;

/// Convenience method that calls `self.with(component)` if `Some(component)` is provided
///
/// # Panics
///
/// Panics if the component hasn't been `register()`ed in the
/// `World`.
#[cfg(feature = "parallel")]
fn maybe_with<C: Component + Send + Sync>(self, c: Option<C>) -> Self
where
Self: Sized,
{
match c {
Some(c) => self.with(c),
None => self,
}
}

/// Convenience method that calls `self.with(component)` if `Some(component)` is provided
///
/// # Panics
///
/// Panics if the component hasn't been `register()`ed in the
/// `World`.
#[cfg(not(feature = "parallel"))]
fn maybe_with<C: Component>(self, c: Option<C>) -> Self
where
Self: Sized,
{
match c {
Some(c) => self.with(c),
None => self,
}
}

/// Finishes the building and returns the entity.
fn build(self) -> Entity;
}
Expand Down

0 comments on commit 1fd81cd

Please sign in to comment.