"Conflicting implimentations" for Into trait
SDL2 has this great method:
pub fn draw_points<'a, P: Into<&'a [Point]>>(
&mut self,
points: P
) -> Result<(), String>
I have my own struct CellNode and I'd like to be able to pass a Vector<CellNode> to draw_points. Here's my attempt:
use sdl2::rect::Point;
use core::convert::Into;
struct CellNode {
//position in the form (x,y)
pos: (i32, i32)
}
impl<Point, CellNode> Into<Point> for CellNode {
fn into(self) -> Point {
return Point::new(self.pos.0, self.pos.y);
}
}
However, I get the errors:
|
15 | impl<Point, CellNode> Into<Point> for CellNode {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate core:
- impl<T, U> std::convert::Into<U> for T
where U: std::convert::From<T>;
error[E0210]: type parameter `CellNode` must be usedas the type parameter for some local type (e.g., `MyStruct<CellNode>`)
--> src/lib/biology.rs:15:1
|
15 | impl<Point, CellNode> Into<Point> for CellNode {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `CellNode` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter
Is this becausePoint already has an into? Did I declare it wrong? Help would be very appreciated :) thanks.
Posted Apr 11, 2019, 7:56 AM UTC
Here's an example which works. Note I'm declaring my own Point in place of the actual SDL version as I don't have the SDL2 library to hand.
Hope that helps!