Skip to content

Commit

Permalink
Auto merge of #176 - nical:reprc, r=emilio
Browse files Browse the repository at this point in the history
Make euclid types repr(C).

This will facilitate exposing euclid types through ffi.

<!-- 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/176)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Feb 7, 2017
2 parents 8947756 + 70ae01e commit e362132
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> support.
#[repr(C)]
#[derive(RustcDecodable, RustcEncodable)]
pub struct Length<T, Unit>(pub T, PhantomData<Unit>);

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ macro_rules! define_matrix {
$(pub $field:ident: T,)+
}
) => (
#[repr(C)]
$(#[$attr])*
pub struct $name<T, $($phantom),+> {
$(pub $field: T,)+
Expand Down
1 change: 1 addition & 0 deletions src/scale_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use std::marker::PhantomData;
/// let one_foot: Length<f32, Inch> = Length::new(12.0);
/// let one_foot_in_mm: Length<f32, Mm> = one_foot * mm_per_inch;
/// ```
#[repr(C)]
#[derive(RustcDecodable, RustcEncodable)]
pub struct ScaleFactor<T, Src, Dst>(pub T, PhantomData<(Src, Dst)>);

Expand Down

0 comments on commit e362132

Please sign in to comment.