leftiness / hex_math

MIT License
4 stars 1 forks source link

impl From<FooStruct> for Point instead of HasValues #65

Closed leftiness closed 7 years ago

leftiness commented 7 years ago

Notes:

It's like... I've got this HasValues<T>. I was thinking... I could
impl From<FooStruct> for Point instead? Do that on the FooStruct file.
Not on the Point file. So you would write this FooStruct in hex_render
or something, and that struct would impl From<FooStruct> for Point.

If I do it that way, I can run inputs of various functions (line,
distance, etc) through From::from() in order to get a Point which I
can use.

It doesn't solve the matter of trying to return an arbitrary
FooStruct. I guess I'll still have to return a Point despite accepting
a FooStruct as an argument. That's not really solved yet, anyway. The
best idea I have is to write a trait that enforces the existence of a
HasUpdate::update(point: &Point) function which would create a new
instance of FooStruct with an updated Point inside.

It's just... I don't really like that I'm doing a bunch of
Point::from(hasValues.values()) all over. fooStruct.into() would be
way nicer. I really should go through my code and see if there are
places where I can use fooStruct.into() instead of
BarStruct::from(fooStruct).
leftiness commented 7 years ago

Duplicate of #72