小编Cha*_*Liu的帖子

我应该使用枚举来模拟多态性还是使用Box <trait>中的trait?

使用enum Axes来限制CoordinateQuaternion

#[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)

polymorphism enums rust

6
推荐指数
2
解决办法
605
查看次数

标签 统计

enums ×1

polymorphism ×1

rust ×1