Skip to content

Commit 9016bdb

Browse files
author
bors-servo
authored
Auto merge of #296 - nical:public-unit, r=kvark
Make the unit a hidden public member instead of private. This is a work-around for the current limitation of not being able to declare static constants from euclid types. There are some RFCs aiming at removing the need to specify phantom types when initializing structs, and we'll eventually be able to evaluate simple functions at compile time, but in the mean time this is the only way to get static constants for euclid types. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/296) <!-- Reviewable:end -->
2 parents 766d2e9 + 1d44b16 commit 9016bdb

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/length.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use core::fmt;
3535
///
3636
/// [`TypedScale`]: struct.TypedScale.html
3737
#[repr(C)]
38-
pub struct Length<T, Unit>(pub T, PhantomData<Unit>);
38+
pub struct Length<T, Unit>(pub T, #[doc(hidden)] pub PhantomData<Unit>);
3939

4040
impl<T: Clone, Unit> Clone for Length<T, Unit> {
4141
fn clone(&self) -> Self {

src/macros.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ macro_rules! define_matrix {
1818
$(#[$attr])*
1919
pub struct $name<T, $($phantom),+> {
2020
$(pub $field: T,)+
21-
_unit: PhantomData<($($phantom),+)>
21+
22+
// Keep this (secretly) public for the few cases where we would like to
23+
// create static constants which currently can't be initialized with a
24+
// function.
25+
#[doc(hidden)]
26+
pub _unit: PhantomData<($($phantom),+)>
2227
}
2328

2429
impl<T: Clone, $($phantom),+> Clone for $name<T, $($phantom),+> {

src/scale.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use {TypedPoint2D, TypedRect, TypedSize2D, TypedVector2D};
3838
/// let one_foot_in_mm: Length<f32, Mm> = one_foot * mm_per_inch;
3939
/// ```
4040
#[repr(C)]
41-
pub struct TypedScale<T, Src, Dst>(pub T, PhantomData<(Src, Dst)>);
41+
pub struct TypedScale<T, Src, Dst>(pub T, #[doc(hidden)] pub PhantomData<(Src, Dst)>);
4242

4343
#[cfg(feature = "serde")]
4444
impl<'de, T, Src, Dst> Deserialize<'de> for TypedScale<T, Src, Dst>

0 commit comments

Comments
 (0)