unsafe fn replace(&mut self, type_info: &TypeInfo, src_ptr: NonNull<u8>) -> Option<*mut u8> {
        match self {
            ComponentData::ScopeOwned(data) => {
                if src_ptr != *data {
                    type_info.drop(data.as_ptr());
                    core::ptr::copy_nonoverlapping(
                        src_ptr.as_ptr(),
                        data.as_ptr(),
                        type_info.layout().size(),
                    );
                }
                None
            }
            ComponentData::WorldOwned(_, data) => {
                if src_ptr != *data {
                    type_info.drop(data.as_ptr());
                    core::ptr::copy_nonoverlapping(
                        src_ptr.as_ptr(),
                        data.as_ptr(),
                        type_info.layout().size(),
                    );
                }
                None
            }
            ComponentData::Removed => {
                // TODO maybe we can use a more efficient storage similar to EntityBuilder?
                let dst_ptr = alloc::alloc::alloc(type_info.layout());
                assert!(!dst_ptr.is_null(), "allocation failed");
                core::ptr::copy_nonoverlapping(
                    src_ptr.as_ptr(),
                    dst_ptr,
                    type_info.layout().size(),
                );
                *self = ComponentData::ScopeOwned(NonNull::new_unchecked(dst_ptr));
                Some(dst_ptr)
            }
        }
    }
// Moves data at src_ptr into the ComponentData, replacing the existing data
// Returns the new pointer if the operation caused the underlying storage to change
Moves data at src_ptr into the ComponentData, replacing the existing data
Returns the new pointer if the operation caused the underlying storage to change
Moves data at src_ptr into the ComponentData replacing the existing data Returns the new pointer if the operation caused the underlying storage to change
unsafe fn replace(&mut self, type_info: &TypeInfo, src_ptr: NonNull<u8>) -> Option<*mut u8> {
        match self {
            ComponentData::ScopeOwned(data) => {
                if src_ptr != *data {
                    type_info.drop(data.as_ptr());
                    core::ptr::copy_nonoverlapping(
                        src_ptr.as_ptr(),
                        data.as_ptr(),
                        type_info.layout().size(),
                    );
                }
                None
            }
            ComponentData::WorldOwned(_, data) => {
                if src_ptr != *data {
                    type_info.drop(data.as_ptr());
                    core::ptr::copy_nonoverlapping(
                        src_ptr.as_ptr(),
                        data.as_ptr(),
                        type_info.layout().size(),
                    );
                }
                None
            }
            ComponentData::Removed => {
                // TODO maybe we can use a more efficient storage similar to EntityBuilder?
                let dst_ptr = alloc::alloc::alloc(type_info.layout());
                assert!(!dst_ptr.is_null(), "allocation failed");
                core::ptr::copy_nonoverlapping(
                    src_ptr.as_ptr(),
                    dst_ptr,
                    type_info.layout().size(),
                );
                *self = ComponentData::ScopeOwned(NonNull::new_unchecked(dst_ptr));
                Some(dst_ptr)
            }
        }
    }
unsafe fn replace ( & mut self , type_info : & TypeInfo , src_ptr : NonNull < u8 > ) -> Option < * mut u8 > { match self { ComponentData :: ScopeOwned ( data ) => { if src_ptr != * data { type_info . drop ( data . as_ptr ( ) ) ; core :: ptr :: copy_nonoverlapping ( src_ptr . as_ptr ( ) , data . as_ptr ( ) , type_info . layout ( ) . size ( ) , ) ; } None } ComponentData :: WorldOwned ( _ , data ) => { if src_ptr != * data { type_info . drop ( data . as_ptr ( ) ) ; core :: ptr :: copy_nonoverlapping ( src_ptr . as_ptr ( ) , data . as_ptr ( ) , type_info . layout ( ) . size ( ) , ) ; } None } ComponentData :: Removed => { // TODO maybe we can use a more efficient storage similar to EntityBuilder? let dst_ptr = alloc :: alloc :: alloc ( type_info . layout ( ) ) ; assert ! ( dst_ptr is_null ( ) " " ) ; core :: ptr :: copy_nonoverlapping ( src_ptr . as_ptr ( ) , dst_ptr , type_info . layout ( ) . size ( ) , ) ; * self = ComponentData :: ScopeOwned ( NonNull :: new_unchecked ( dst_ptr ) ) ; Some ( dst_ptr ) } } }
Moves data at src_ptr into the ComponentData, replacing the existing data
Returns the new pointer if the operation caused the underlying storage to change
Moves data at src_ptr into the ComponentData replacing the existing data Returns the new pointer if the operation caused the underlying storage to change
&mut self
type_info
&TypeInfo
src_ptr
NonNull<u8>
&mut self
type_info
&TypeInfo
src_ptr
NonNull<u8>