使用enum Axes来限制Coordinate和Quaternion:
#[derive(Clone)]
pub enum Axes {
Coordinate {x: f64, y: f64, z: f64, reserve: Vec<f64>,},
Quaternion {x: f64, y: f64, z: f64},
}
impl Axes {
pub fn shift(&mut self, Sample: &Axes) -> () {
let Dup: Axes = self.clone();
match Dup {
Axes::Coordinate {x, y, z, reserve} => {
match &Sample {
Axes::Coordinate {x, y, z, reserve} => {
*self = Axes::Coordinate {x: *x, y: *y, z: *z, reserve: reserve.to_vec()};
}
_ …Run Code Online (Sandbox Code Playgroud)