Why am I getting "the parameter is never used [E0392]"?

I am trying to implement Octree in Rust. Octree is generic in type with the restriction that it should implement a generic attribute:

pub trait Generable<U> { fn generate_children(&self, data: &U) -> Vec<Option<Self>>; } pub enum Octree<T, U> where T: Generable<U>, { Node { data: T, children: Vec<Box<Octree<T, U>>>, }, Empty, Uninitialized, } 

Here is a simplified example reproducing a problem on a playground

This creates an error:

 error[E0392]: parameter `U` is never used --> src/main.rs:5:20 | 5 | pub enum Octree<T, U> | ^ unused type parameter | = help: consider removing `U` or using a marker such as `std::marker::PhantomData` 

Removing U from the signature result means "undeclared name of type" U ".

Am I doing something wrong or is it a mistake? How to do it right?

+7
rust
Aug 17 '15 at 14:47
source share
1 answer

I do not believe that you need one more general type, you want a related type :

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

Aside, Vec<Box<Octree<T>>> is probably one of the additional levels of indirection - you can just use Vec<Octree<T>> .

+5
Aug 17 '15 at 16:54
source share



All Articles