Why am I getting “parameter is never used [E0392]”?

后端 未结 1 1783
我在风中等你
我在风中等你 2020-12-20 14:24

I\'m trying to implement an Octree in Rust. The Octree is generic over a type with a constraint that it should implement a generic trait:

pub trait Generable         


        
1条回答
  •  执笔经年
    2020-12-20 14:48

    I don't believe you want another generic here, you want an associated type:

    pub trait Generable {
        type From;
        fn generate_children(&self, data: &Self::From) -> Vec>
        where
            Self: Sized;
    }
    
    pub enum Octree
    where
        T: Generable,
    {
        Node {
            data: T,
            children: Vec>>,
        },
        Empty,
        Uninitialized,
    }
    
    fn main() {}
    

    As an aside, Vec>> is probably one level extra of indirection — you can just use Vec>.

    0 讨论(0)
提交回复
热议问题