pub struct Handle<T> { /* private fields */ }Expand description
A handle for an object
You can get an instance of Handle by inserting an object into a store. A
handle dereferences to the object it points to, via its Deref
implementation.
Equality and Identity
Equality of Handles is defined via the objects they reference. If those
objects are equal, the Handles are considered equal.
This is distinct from the identity of the referenced objects. Two objects might be equal, but they might be have been created at different times, for different reasons, and thus live in different slots in the storage. This is a relevant distinction when validating objects, as equal but not identical objects might be a sign of a bug.
You can compare the identity of two objects through their Handles, by
comparing the values returned by Handle::id.
Implementations§
source§impl<T> Handle<T>
impl<T> Handle<T>
sourcepub fn id(&self) -> ObjectId
pub fn id(&self) -> ObjectId
Access this pointer’s unique id
Examples found in repository?
206 207 208 209 210 211 212 213 214 215 216 217 218
fn get<T>(&mut self, handle: &Handle<T>) -> Option<Inner<T>>
where
T: HasPartial + 'static,
{
self.map().get(&handle.id()).cloned()
}
fn insert<T>(&mut self, handle: &Handle<T>, inner: Inner<T>)
where
T: HasPartial + 'static,
{
self.map().insert(handle.id(), inner);
}More examples
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
fn get<T: 'static>(&mut self, key: &Handle<T>) -> Option<&Handle<T>> {
let map = self
.0
.entry::<BTreeMap<ObjectId, Handle<T>>>()
.or_insert_with(BTreeMap::new);
map.get(&key.id())
}
fn insert<T: 'static>(&mut self, key: Handle<T>, value: Handle<T>) {
let map = self
.0
.entry::<BTreeMap<ObjectId, Handle<T>>>()
.or_insert_with(BTreeMap::new);
map.insert(key.id(), value);
}168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
pub fn insert(
&mut self,
handle: Handle<GlobalCurve>,
range: RangeOnPath,
approx: GlobalCurveApprox,
) -> GlobalCurveApprox {
self.inner.insert((handle.id(), range), approx.clone());
approx
}
/// Access the approximation for the given [`GlobalCurve`], if available
pub fn get(
&self,
handle: Handle<GlobalCurve>,
range: RangeOnPath,
) -> Option<GlobalCurveApprox> {
self.inner.get(&(handle.id(), range)).cloned()
}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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
fn check_curve_identity(half_edge: &HalfEdge) -> Result<(), Self> {
let back_curve = half_edge.back().curve();
let front_curve = half_edge.front().curve();
if back_curve.id() != front_curve.id() {
return Err(Self::CurveMismatch {
back_curve: back_curve.clone(),
front_curve: front_curve.clone(),
});
}
Ok(())
}
fn check_global_curve_identity(half_edge: &HalfEdge) -> Result<(), Self> {
let global_curve_from_curve = half_edge.curve().global_form();
let global_curve_from_global_form = half_edge.global_form().curve();
if global_curve_from_curve.id() != global_curve_from_global_form.id() {
return Err(Self::GlobalCurveMismatch {
global_curve_from_curve: global_curve_from_curve.clone(),
global_curve_from_global_form: global_curve_from_global_form
.clone(),
});
}
Ok(())
}
fn check_global_vertex_identity(half_edge: &HalfEdge) -> Result<(), Self> {
let global_vertices_from_vertices = {
let (global_vertices_from_vertices, _) =
VerticesInNormalizedOrder::new(
half_edge
.vertices()
.each_ref_ext()
.map(|vertex| vertex.global_form().clone()),
);
global_vertices_from_vertices.access_in_normalized_order()
};
let global_vertices_from_global_form = half_edge
.global_form()
.vertices()
.access_in_normalized_order();
let ids_from_vertices = global_vertices_from_vertices
.each_ref_ext()
.map(|global_vertex| global_vertex.id());
let ids_from_global_form = global_vertices_from_global_form
.each_ref_ext()
.map(|global_vertex| global_vertex.id());
if ids_from_vertices != ids_from_global_form {
return Err(Self::GlobalVertexMismatch {
global_vertices_from_vertices,
global_vertices_from_global_form,
});
}
Ok(())
}64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn check_surface_identity(face: &Face) -> Result<(), Self> {
let surface = face.surface();
for interior in face.interiors() {
if surface.id() != interior.surface().id() {
return Err(Self::SurfaceMismatch {
surface: surface.clone(),
interior: interior.clone(),
face: face.clone(),
});
}
}
Ok(())
}sourcepub fn clone_object(&self) -> Twhere
T: Clone,
pub fn clone_object(&self) -> Twhere
T: Clone,
Return a clone of the object this handle refers to
Examples found in repository?
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
fn transform_with_cache(
self,
transform: &Transform,
objects: &mut Service<Objects>,
cache: &mut TransformCache,
) -> Self {
if let Some(object) = cache.get(&self) {
return object.clone();
}
let transformed = self
.clone_object()
.transform_with_cache(transform, objects, cache)
.insert(objects);
cache.insert(self.clone(), transformed.clone());
transformed
}More examples
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn check_position(
vertex: &Vertex,
config: &ValidationConfig,
) -> Result<(), Self> {
let curve_position_as_surface = vertex
.curve()
.path()
.point_from_path_coords(vertex.position());
let surface_position = vertex.surface_form().position();
let distance = curve_position_as_surface.distance_to(&surface_position);
if distance > config.identical_max_distance {
return Err(Self::PositionMismatch {
vertex: vertex.clone(),
surface_vertex: vertex.surface_form().clone_object(),
curve_position_as_surface,
distance,
});
}
Ok(())
}
}
/// [`SurfaceVertex`] validation error
#[derive(Clone, Debug, thiserror::Error)]
pub enum SurfaceVertexValidationError {
/// Mismatch between position and position of global form
#[error(
"`SurfaceVertex` position doesn't match position of its global form\n\
- `SurfaceVertex`: {surface_vertex:#?}\n\
- `GlobalVertex`: {global_vertex:#?}\n\
- `SurfaceVertex` position as global: {surface_position_as_global:?}\n\
- Distance between the positions: {distance}"
)]
PositionMismatch {
/// The surface vertex
surface_vertex: SurfaceVertex,
/// The mismatched global vertex
global_vertex: GlobalVertex,
/// The surface position converted into a global position
surface_position_as_global: Point<3>,
/// The distance between the positions
distance: Scalar,
},
}
impl SurfaceVertexValidationError {
fn check_position(
surface_vertex: &SurfaceVertex,
config: &ValidationConfig,
) -> Result<(), Self> {
let surface_position_as_global = surface_vertex
.surface()
.geometry()
.point_from_surface_coords(surface_vertex.position());
let global_position = surface_vertex.global_form().position();
let distance = surface_position_as_global.distance_to(&global_position);
if distance > config.identical_max_distance {
return Err(Self::PositionMismatch {
surface_vertex: surface_vertex.clone(),
global_vertex: surface_vertex.global_form().clone_object(),
surface_position_as_global,
distance,
});
}
Ok(())
}Trait Implementations§
source§impl Extend<Handle<Face>> for FaceSet
impl Extend<Handle<Face>> for FaceSet
source§fn extend<T: IntoIterator<Item = Handle<Face>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Handle<Face>>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl From<Handle<GlobalCurve>> for Object<BehindHandle>
impl From<Handle<GlobalCurve>> for Object<BehindHandle>
source§fn from(object: Handle<GlobalCurve>) -> Self
fn from(object: Handle<GlobalCurve>) -> Self
source§impl From<Handle<GlobalEdge>> for Object<BehindHandle>
impl From<Handle<GlobalEdge>> for Object<BehindHandle>
source§fn from(object: Handle<GlobalEdge>) -> Self
fn from(object: Handle<GlobalEdge>) -> Self
source§impl From<Handle<GlobalVertex>> for Object<BehindHandle>
impl From<Handle<GlobalVertex>> for Object<BehindHandle>
source§fn from(object: Handle<GlobalVertex>) -> Self
fn from(object: Handle<GlobalVertex>) -> Self
source§impl From<Handle<SurfaceVertex>> for Object<BehindHandle>
impl From<Handle<SurfaceVertex>> for Object<BehindHandle>
source§fn from(object: Handle<SurfaceVertex>) -> Self
fn from(object: Handle<SurfaceVertex>) -> Self
source§impl<T> From<Handle<T>> for HandleWrapper<T>
impl<T> From<Handle<T>> for HandleWrapper<T>
source§impl<T> From<HandleWrapper<T>> for Handle<T>
impl<T> From<HandleWrapper<T>> for Handle<T>
source§fn from(wrapper: HandleWrapper<T>) -> Self
fn from(wrapper: HandleWrapper<T>) -> Self
source§impl<'r> ObjectIters<'r> for Handle<Curve>
impl<'r> ObjectIters<'r> for Handle<Curve>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<Cycle>
impl<'r> ObjectIters<'r> for Handle<Cycle>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<Face>
impl<'r> ObjectIters<'r> for Handle<Face>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<GlobalCurve>
impl<'r> ObjectIters<'r> for Handle<GlobalCurve>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<GlobalVertex>
impl<'r> ObjectIters<'r> for Handle<GlobalVertex>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<HalfEdge>
impl<'r> ObjectIters<'r> for Handle<HalfEdge>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<Shell>
impl<'r> ObjectIters<'r> for Handle<Shell>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<Surface>
impl<'r> ObjectIters<'r> for Handle<Surface>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<'r> ObjectIters<'r> for Handle<Vertex>
impl<'r> ObjectIters<'r> for Handle<Vertex>
source§fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters<'_>>
source§fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> ⓘ
source§fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
fn global_vertex_iter(&'r self) -> Iter<&'r GlobalVertex> ⓘ
source§impl<T> Ord for Handle<T>where
T: Ord,
impl<T> Ord for Handle<T>where
T: Ord,
source§impl<T> PartialEq<Handle<T>> for Handle<T>where
T: PartialEq,
impl<T> PartialEq<Handle<T>> for Handle<T>where
T: PartialEq,
source§impl<T> PartialOrd<Handle<T>> for Handle<T>where
T: PartialOrd,
impl<T> PartialOrd<Handle<T>> for Handle<T>where
T: PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl Sweep for Handle<Curve>
impl Sweep for Handle<Curve>
source§fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
_: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
_: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
source§impl Sweep for Handle<Face>
impl Sweep for Handle<Face>
source§fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
source§impl Sweep for Handle<GlobalVertex>
impl Sweep for Handle<GlobalVertex>
§type Swept = (Handle<GlobalEdge>, [Handle<GlobalVertex>; 2])
type Swept = (Handle<GlobalEdge>, [Handle<GlobalVertex>; 2])
source§fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
source§impl Sweep for Handle<Sketch>
impl Sweep for Handle<Sketch>
source§fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
fn sweep_with_cache(
self,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
objects: &mut Service<Objects>
) -> Self::Swept
source§impl<T> TransformObject for Handle<T>where
T: Clone + Insert + TransformObject + 'static,
impl<T> TransformObject for Handle<T>where
T: Clone + Insert + TransformObject + 'static,
source§fn transform_with_cache(
self,
transform: &Transform,
objects: &mut Service<Objects>,
cache: &mut TransformCache
) -> Self
fn transform_with_cache(
self,
transform: &Transform,
objects: &mut Service<Objects>,
cache: &mut TransformCache
) -> Self
source§fn transform(self, transform: &Transform, objects: &mut Service<Objects>) -> Self
fn transform(self, transform: &Transform, objects: &mut Service<Objects>) -> Self
impl<T> Eq for Handle<T>where
T: Eq,
impl<T> Send for Handle<T>
impl<T> Sync for Handle<T>
Auto Trait Implementations§
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.