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

Insertion documentation #477

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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