lex_lib/vec2generic.rs
1//! Vector2 generic.
2
3/// Generic Vector2.
4///
5/// Requires for the Type to derive `Debug, Clone, PartialEq` and implement `Default` trait
6///
7/// Doesn't overload operators like the other Vector2s
8#[derive(Debug, Clone, PartialEq)]
9pub struct Vec2generic<T>{
10 /// X value.
11 pub x: T,
12 /// Y value.
13 pub y: T
14}
15
16impl<T: Clone> Vec2generic<T>{
17 /// Creates a new [`Vec2generic`] with x and y defined.
18 ///
19 /// use `default()` for a default initialized.
20 pub fn new(x: T, y: T) -> Self {
21 Self{
22 x,
23 y
24 }
25 }
26
27 /// Puts x into y and y into x
28 pub fn flip(&mut self){
29 let tmp = self.x.clone();
30 self.x = self.y.clone();
31 self.y = tmp;
32 }
33}
34
35impl<T: Default> Default for Vec2generic<T> {
36 /// Creates a new [`Vec2generic`] with x and y initialized with the Type default.
37 fn default() -> Self {
38 Self{
39 x: T::default(),
40 y: T::default()
41 }
42 }
43}