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<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 the issue on the Playground
This generates 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 the U
from the signature results in "undeclared type name 'U'".
Am I doing something wrong or is it a bug? How to do this properly?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…