Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom Debug impl for Coord<Space> #1320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion fontdrasil/src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,23 @@ pub struct UserSpace;
pub struct NormalizedSpace;

/// A coordinate in some coordinate space.
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Serialize, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Coord<Space> {
coord: OrderedFloat<f64>,
// we want to be covariant but also Send + Sync. See
// <https://doc.rust-lang.org/1.74.0/nomicon/phantom-data.html#table-of-phantomdata-patterns>
space: PhantomData<fn() -> Space>,
}

impl<Space: Debug + Default> Debug for Coord<Space> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Coord")
.field("coord", &self.coord)
.field("space", &Space::default())
.finish()
}
}

/// A coordinate in design space.
pub type DesignCoord = Coord<DesignSpace>;
/// A coordinate in user space
Expand Down