Skip to content

Commit

Permalink
Merge #477
Browse files Browse the repository at this point in the history
477: Insertion documentation r=Xaeroxe a=Aceeri

Fixes #475

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/slide-rs/specs/477)
<!-- Reviewable:end -->


Co-authored-by: Aceeri <[email protected]>
  • Loading branch information
bors[bot] and Aceeri committed Sep 20, 2018
2 parents d2fc633 + a4d0293 commit 72ae9a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ where

/// Inserts new data for a given `Entity`.
/// Returns the result of the operation as a `InsertResult<T>`
///
/// If a component already existed for the given `Entity`, then it will
/// be overwritten with the new component. If it did overwrite, then the
/// result will contain `Some(T)` where `T` is the previous component.
pub fn insert(&mut self, e: Entity, mut v: T) -> InsertResult<T> {
if self.entities.is_alive(e) {
let id = e.id();
Expand Down
3 changes: 3 additions & 0 deletions src/world/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct LazyBuilder<'a> {

impl<'a> Builder for LazyBuilder<'a> {
/// Inserts a component using [`LazyUpdate`].
///
/// If a component was already associated with the entity, it will
/// overwrite the previous component.
fn with<C>(self, component: C) -> Self
where
C: Component + Send + Sync,
Expand Down
7 changes: 7 additions & 0 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ impl<'a> Iterator for CreateIter<'a> {
pub trait Builder {
/// Appends a component and associates it with the entity.
///
/// If a component was already associated with the entity, it should
/// overwrite the previous component.
///
/// # Panics
///
/// Panics if the component hasn't been `register()`ed in the
Expand Down Expand Up @@ -95,6 +98,10 @@ pub struct EntityBuilder<'a> {
}

impl<'a> Builder for EntityBuilder<'a> {
/// Inserts a component for this entity.
///
/// If a component was already associated with the entity, it will
/// overwrite the previous component.
#[inline]
fn with<T: Component>(self, c: T) -> Self {
{
Expand Down

0 comments on commit 72ae9a6

Please sign in to comment.