Skip to content

Commit

Permalink
Struct Point conversion to tuple (ixmilia#47)
Browse files Browse the repository at this point in the history
Added tuple conversion for struct Point for one liner extraction of its
inner data by introducing method "tuple".

This change is just for convenience to downstream user in getting
coordinates like the examples below:

```rust
let (x, _, z) = p.tuple();
let (_, y, z) = p.tuple();
let (x, y, _) = p.tuple();
```
  • Loading branch information
mrghosti3 authored Oct 13, 2023
1 parent 1fe435a commit f7ce4e4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,24 @@ impl Point {

Ok(())
}

pub fn tuple(&self) -> (f64, f64, f64) {
(self.x, self.y, self.z)
}
}

#[cfg(test)]
mod tests {
use super::*;

/// Tests whether tuple conversion works as intended and Point doesn't get consumed.
#[test]
fn tuple_conversion_case() {
let p = Point::new(1.0, 1.0, 1.0);
let t: (f64, f64, f64) = p.tuple();

dbg!(&p);
dbg!(&t);
assert_eq!(t, p.tuple())
}
}

0 comments on commit f7ce4e4

Please sign in to comment.