Skip to content

Commit

Permalink
Merge pull request #1298 from hannobraun/handle
Browse files Browse the repository at this point in the history
Improve `Debug` implementation of `Handle`
  • Loading branch information
hannobraun authored Nov 2, 2022
2 parents d717e85 + 6923e05 commit bc57d86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
27 changes: 14 additions & 13 deletions crates/fj-kernel/src/storage/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ impl<T> Handle<T> {
{
self.deref().clone()
}

/// Return a `Debug` implementation with full debug info
pub fn full_debug(&self) -> impl fmt::Debug
where
T: fmt::Debug,
{
// It would be nicer to return a struct that implements `Debug`, as that
// would cut down on allocations, but this will work for now.
format!("{:?} -> {:?}", self.id(), self.deref())
}
}

impl<T> Deref for Handle<T> {
Expand Down Expand Up @@ -138,7 +128,10 @@ where
}
}

impl<T> fmt::Debug for Handle<T> {
impl<T> fmt::Debug for Handle<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let name = {
let type_name = type_name::<T>();
Expand All @@ -148,8 +141,13 @@ impl<T> fmt::Debug for Handle<T> {
}
};
let id = self.id().0;
let object = self.deref();

write!(f, "{name} @ {id:#x}")?;
if f.alternate() {
write!(f, "{name} @ {id:#x} => {object:#?}")?;
} else {
write!(f, "{name} @ {id:#x}")?;
}

Ok(())
}
Expand Down Expand Up @@ -272,7 +270,10 @@ impl<T> PartialOrd for HandleWrapper<T> {
}
}

impl<T> fmt::Debug for HandleWrapper<T> {
impl<T> fmt::Debug for HandleWrapper<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
Expand Down
24 changes: 8 additions & 16 deletions crates/fj-kernel/src/validate/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ pub enum HalfEdgeValidationError {
/// [`HalfEdge`] vertices are not defined on the same `Curve`
#[error(
"`HalfEdge` vertices are not defined on the same `Curve`\n\
- `Curve` of back vertex: {:?}\n\
- `Curve` of front vertex: {:?}",
.back_curve.full_debug(),
.front_curve.full_debug(),
- `Curve` of back vertex: {back_curve:#?}\n\
- `Curve` of front vertex: {front_curve:#?}"
)]
CurveMismatch {
/// The curve of the [`HalfEdge`]'s back vertex
Expand All @@ -62,10 +60,8 @@ pub enum HalfEdgeValidationError {
#[error(
"Global form of `HalfEdge`'s `Curve` does not match `GlobalCurve` of \n\
the `HalfEdge`'s `GlobalEdge`\n\
- `GlobalCurve` from `Curve`: {:?}\n\
- `GlobalCurve` from `GlobalEdge`: {:?}",
.global_curve_from_curve.full_debug(),
.global_curve_from_global_form.full_debug(),
- `GlobalCurve` from `Curve`: {global_curve_from_curve:#?}\n\
- `GlobalCurve` from `GlobalEdge`: {global_curve_from_global_form:#?}",
)]
GlobalCurveMismatch {
/// The [`GlobalCurve`] from the [`HalfEdge`]'s [`Curve`]
Expand All @@ -79,14 +75,10 @@ pub enum HalfEdgeValidationError {
#[error(
"Global forms of `HalfEdge` vertices do not match vertices of \n\
`HalfEdge`'s global form\n\
- `GlobalVertex` objects from `Vertex` objects: {:?}\n\
- `GlobalVertex` objects from `GlobalEdge`: {:?}",
.global_vertices_from_vertices
.each_ref_ext()
.map(|vertex| vertex.full_debug()),
.global_vertices_from_global_form
.each_ref_ext()
.map(|vertex| vertex.full_debug()),
- `GlobalVertex` objects from `Vertex` objects: \
{global_vertices_from_vertices:#?}\n\
- `GlobalVertex` objects from `GlobalEdge`: \
{global_vertices_from_global_form:#?}"
)]
GlobalVertexMismatch {
/// The [`GlobalVertex`] from the [`HalfEdge`]'s vertices
Expand Down
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/validate/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ pub enum VertexValidationError {
/// Mismatch between the surface's of the curve and surface form
#[error(
"Surface form of vertex must be defined on same surface as curve\n\
`- Surface` of curve: {:?}\n\
`- Surface` of surface form: {:?}",
.curve_surface.full_debug(),
.surface_form_surface.full_debug(),
`- Surface` of curve: {curve_surface:#?}\n\
`- Surface` of surface form: {surface_form_surface:#?}"
)]
SurfaceMismatch {
/// The surface of the vertex' curve
Expand Down

0 comments on commit bc57d86

Please sign in to comment.