pub struct Mesh {
pub positions: Option<Vec<Vec3>>,
pub indices: Option<Vec<u32>>,
pub uv: Option<Vec<Vec2>>,
pub colors: Option<Vec<U8Vec4>>
}
pub trait MeshBuilder {
fn build_mesh(&self) -> Mesh;
}
impl<T: Borrow<impl MeshBuilder>> From<T> for Mesh {
fn from(mesh_builder: T) -> Self {
mesh_builder.build_mesh()
}
}
I want to express that for any type T that implements MeshBuilder, T, &T, &mut T etc. can be converted to Mesh, but this gives me:
error[E0207]: the type parameter `impl MeshBuilder` is not constrained by the impl trait, self type, or predicates
--> src/mesh.rs:16:16
|
16 | impl<T: Borrow<impl MeshBuilder>> From<T> for Mesh {
|
and
error[E0119]: conflicting implementations of trait `std::convert::From<mesh::Mesh>` for type `mesh::Mesh`
--> src/mesh.rs:16:1
|
16 | impl<T: Borrow<impl MeshBuilder>> From<T> for Mesh {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
Is there no way to use the Borrow trait to do this all in one impl block?