euclid icon indicating copy to clipboard operation
euclid copied to clipboard

Size2D: how to access width, height as `Length<T, U>`?

Open wez opened this issue 5 years ago • 1 comments

I'm looking for (sort of) the inverse of Size2D::from_lengths, but it seems like there isn't a convenient way to access the fields in this way.

The doc comment for Size2D::to_array suggests that it exposes the Length, but it just returns elements of type T.

I'd like to avoid having to manually construct a length where the fields are accessed as this is potentially error prone.

Something like this, but with much better names:

pub fn width_length(&self) -> Length<T, U> {
     Length::new(self.width)
}
pub fn height_length(&self) -> Length<T, U> {
     Length::new(self.height)
}

wez avatar Dec 10 '19 16:12 wez

The strongly typed getters returning Length<T, U> used to exist but were removed in part because their names weren't very ergonomic (foo.width_typed()) and more importantly becaused it seemed that nobody used them at all (maybe due to the bad ergonomics).

We could re-introduce them since this issues shows that there is some interest in using them.

My preference would be fn get_x(&self) -> Length<T, U>, fn get_width(&self) -> Length<T, U>, etc. applied consistently so that all scalar member and method accessors foo/foo() yield a raw scalar while get_foo() methods return a Length.

The documentation of to_array is a mistake. We probably deleted the wrong lines when getting rid of the typed accessor and the documentation of width_typed ended up on top of the wrong function.

nical avatar Dec 12 '19 10:12 nical