diff --git a/src/length.rs b/src/length.rs index f2c89d3c..e14e7106 100644 --- a/src/length.rs +++ b/src/length.rs @@ -33,6 +33,7 @@ use std::fmt; /// another. See the `ScaleFactor` docs for an example. // Uncomment the derive, and remove the macro call, once heapsize gets // PhantomData support. +#[repr(C)] #[derive(RustcDecodable, RustcEncodable)] pub struct Length(pub T, PhantomData); diff --git a/src/lib.rs b/src/lib.rs index 09a1e3e5..55c98528 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,9 @@ //! Client code typically creates a set of aliases for each type and doesn't need //! to deal with the specifics of typed units further. For example: //! +//! All euclid types are marked #[repr(C)] in order to facilitate exposing them to +//! foreign function interfaces (provided the underlying scalar type is also repr(C)). +//! //! ```rust //! use euclid::*; //! pub struct ScreenSpace; diff --git a/src/macros.rs b/src/macros.rs index 8984c4e1..26471a63 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -14,6 +14,7 @@ macro_rules! define_matrix { $(pub $field:ident: T,)+ } ) => ( + #[repr(C)] $(#[$attr])* pub struct $name { $(pub $field: T,)+ diff --git a/src/scale_factor.rs b/src/scale_factor.rs index bd004886..d41395ea 100644 --- a/src/scale_factor.rs +++ b/src/scale_factor.rs @@ -36,6 +36,7 @@ use std::marker::PhantomData; /// let one_foot: Length = Length::new(12.0); /// let one_foot_in_mm: Length = one_foot * mm_per_inch; /// ``` +#[repr(C)] #[derive(RustcDecodable, RustcEncodable)] pub struct ScaleFactor(pub T, PhantomData<(Src, Dst)>);