Joey9801 / igc-rs

MIT License
6 stars 4 forks source link

Allow converting borrowed raw coordinates into floats #36

Closed dbrgn closed 5 years ago

dbrgn commented 5 years ago

Previously converting raw coordinates would always consume them.

For example, this does not currently work:

let lat: f64 = b.pos.lat.into();
let lon: f64 = b.pos.lon.into();

...because the first line consumes pos.

Right now I have to resort to this awkward destructuring workaround:

let RawPosition { lat: raw_lat, lon: raw_lon } = b.pos;
let lat = raw_lat.into();
let lon = raw_lon.into();

...and afterwards I cannot use b.pos anymore because it has been consumed. OK in my case since I only use the floats anyways.

I created a simple macro to avoid duplication. Let me know if you prefer a non-macro approach.

dbrgn commented 5 years ago

Rebased and formatting fixed. I hope the tests pass now.

If this is merged, do you plan a new release? Would be great to have this functionality available soon.

Joey9801 commented 5 years ago

I think a more elegant solution to your problem would be to just implement Copy for for RawLatitude/RawLongitude/RawCoord. RawCoord only has a u16, u8, and an instance of an enum with 4 variants + no data -> it should easily fit inside a 32 bit word/half word, making an implicit copy dirt cheap.

Joey9801 commented 5 years ago

igc 0.2.2 is published on crates.io, which contains a Copy impl for RawCoord + its newtypes.

dbrgn commented 5 years ago

Thanks! That's also a good solution :slightly_smiling_face: