Skip to content

Commit

Permalink
Add impl GeckoStyleCoordConvertible for Either<A, B>
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Nov 18, 2016
1 parent 22aebdf commit 73eabad
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/style/gecko/values.rs
Expand Up @@ -10,6 +10,7 @@ use gecko_bindings::structs::{NS_RADIUS_CLOSEST_SIDE, NS_RADIUS_FARTHEST_SIDE};
use gecko_bindings::structs::nsStyleCoord;
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
use std::cmp::max;
use values::Either;
use values::computed::{LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, Angle};
use values::computed::basic_shape::ShapeRadius;
Expand All @@ -31,6 +32,21 @@ pub trait GeckoStyleCoordConvertible : Sized {
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self>;
}

impl<A: GeckoStyleCoordConvertible, B: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for Either<A, B> {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self {
Either::First(ref v) => v.to_gecko_style_coord(coord),
Either::Second(ref v) => v.to_gecko_style_coord(coord),
}
}

fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
A::from_gecko_style_coord(coord)
.map(Either::First)
.or_else(|| B::from_gecko_style_coord(coord).map(Either::Second))
}
}

impl GeckoStyleCoordConvertible for LengthOrPercentage {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
let value = match *self {
Expand Down

0 comments on commit 73eabad

Please sign in to comment.