Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wez opened this issue Dec 10, 2019 · 1 comment
Open

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

wez opened this issue Dec 10, 2019 · 1 comment

Comments

@wez
Copy link

wez commented Dec 10, 2019

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)
}
@nical
Copy link
Contributor

nical commented Dec 12, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants