#[allow(unused_imports)] use crate::world::World;
use bevy_ptr::OwningPtr;
use std::{alloc::Layout, any::type_name};
pub trait Data: 'static + Send + Sync {}
#[allow(unused)]
pub struct DataInfo {
name: &'static str,
layout: Layout,
drop_fn: Option<unsafe fn(OwningPtr<'_>)>,
}
unsafe fn drop_data<T: Data>(ptr: OwningPtr<'_>) { unsafe {
OwningPtr::drop_as::<T>(ptr)
}}
impl DataInfo {
pub fn deafult_for<T: Data>() -> Self {
Self {
name: type_name::<T>(),
layout: Layout::new::<T>(),
drop_fn: Some(drop_data::<T>),
}
}
pub fn drop_fn(&self) -> Option<unsafe fn(OwningPtr<'_>)> {
self.drop_fn
}
pub fn layout(&self) -> Layout {
self.layout
}
pub fn name(&self) -> &'static str {
self.name
}
pub fn new(
name: &'static str,
layout: Layout,
drop_fn: Option<unsafe fn(OwningPtr<'_>)>,
) -> DataInfo {
Self {
layout,
drop_fn,
name,
}
}
}