pub struct Store<T> { /* private fields */ }Expand description
Append-only object storage
Implementations§
source§impl<T> Store<T>
impl<T> Store<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new instance of Store
Equivalent to calling Store::with_block_size with a default block
size.
Examples found in repository?
More examples
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
fn default() -> Self {
let mut store: Store<Surface> = Store::new();
let xy_plane = store.reserve();
store.insert(
xy_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
}),
);
let xz_plane = store.reserve();
store.insert(
xz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
}),
);
let yz_plane = store.reserve();
store.insert(
yz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
}),
);
Self {
store,
xy_plane,
xz_plane,
yz_plane,
}
}sourcepub fn with_block_size(block_size: usize) -> Self
pub fn with_block_size(block_size: usize) -> Self
Construct a new instance of Store using the provided block size
sourcepub fn reserve(&self) -> Handle<T>
pub fn reserve(&self) -> Handle<T>
Reserve a slot for an object in the store
This method returns a handle to the reserved slot. That handle does not refer to an object yet! Attempting to dereference the handle before it has been used to insert an object into the store, will result in a panic.
Usually, you’d acquire one handle, then immediately use it to insert an
object using Store::insert. The methods are separate to support more
advanced use cases, like inserting objects that refer to each other.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub fn reserve(&self) -> Handle<Surface> {
self.store.reserve()
}
/// Insert a [`Surface`] into the store
pub fn insert(&mut self, handle: Handle<Surface>, surface: Surface) {
self.store.insert(handle, surface);
}
/// Access the xy-plane
pub fn xy_plane(&self) -> Handle<Surface> {
self.xy_plane.clone()
}
/// Access the xz-plane
pub fn xz_plane(&self) -> Handle<Surface> {
self.xz_plane.clone()
}
/// Access the yz-plane
pub fn yz_plane(&self) -> Handle<Surface> {
self.yz_plane.clone()
}
}
impl Default for Surfaces {
fn default() -> Self {
let mut store: Store<Surface> = Store::new();
let xy_plane = store.reserve();
store.insert(
xy_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
}),
);
let xz_plane = store.reserve();
store.insert(
xz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
}),
);
let yz_plane = store.reserve();
store.insert(
yz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
}),
);
Self {
store,
xy_plane,
xz_plane,
yz_plane,
}
}sourcepub fn insert(&mut self, handle: Handle<T>, object: T)
pub fn insert(&mut self, handle: Handle<T>, object: T)
Insert an object into the store
Panics
Panics, if the passed Handle does not refer to a reserved slot. This
can only be the case, if the handle has been used to insert an object
before.
Examples found in repository?
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub fn insert(&mut self, handle: Handle<Surface>, surface: Surface) {
self.store.insert(handle, surface);
}
/// Access the xy-plane
pub fn xy_plane(&self) -> Handle<Surface> {
self.xy_plane.clone()
}
/// Access the xz-plane
pub fn xz_plane(&self) -> Handle<Surface> {
self.xz_plane.clone()
}
/// Access the yz-plane
pub fn yz_plane(&self) -> Handle<Surface> {
self.yz_plane.clone()
}
}
impl Default for Surfaces {
fn default() -> Self {
let mut store: Store<Surface> = Store::new();
let xy_plane = store.reserve();
store.insert(
xy_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
}),
);
let xz_plane = store.reserve();
store.insert(
xz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
}),
);
let yz_plane = store.reserve();
store.insert(
yz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
}),
);
Self {
store,
xy_plane,
xz_plane,
yz_plane,
}
}Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Store<T>
impl<T> Send for Store<T>where
T: Send + Sync,
impl<T> Sync for Store<T>where
T: Send + Sync,
impl<T> Unpin for Store<T>
impl<T> !UnwindSafe for Store<T>
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.