Skip to content

Instantly share code, notes, and snippets.

@Sushisource
Created April 12, 2018 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sushisource/7e1441c56d56706386efcc48fc9ea0d5 to your computer and use it in GitHub Desktop.
Save Sushisource/7e1441c56d56706386efcc48fc9ea0d5 to your computer and use it in GitHub Desktop.
Rust from/into generic impl
error[E0119]: conflicting implementations of trait `std::convert::Into<ggez::graphics::Rect>` for type `&_`:
--> src\dungeongen\rooms.rs:143:1
|
143 | impl<'a, T: CenterOriginRect> Into<Rect> for &'a T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T, U> std::convert::Into<U> for T
where U: std::convert::From<T>;
= note: downstream crates may implement trait `std::convert::From<&_>` for type `ggez::graphics::Rect`
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter
--> src\dungeongen\rooms.rs:143:1
|
143 | / impl<'a, T: CenterOriginRect> Into<Rect> for &'a T {
144 | | fn into(self) -> Rect {
145 | | Rect {
146 | | // GGEZ Rects have a top-left origin
... |
152 | | }
153 | | }
| |_^
error: aborting due to 2 previous errors
trait CenterOriginRect {
fn center(&self) -> Point;
fn width(&self) -> Meters;
fn height(&self) -> Meters;
}
impl CenterOriginRect for Room {
fn center(&self) -> Point { self.center }
fn width(&self) -> f32 { self.width }
fn height(&self) -> f32 { self.height }
}
impl<'a, T: CenterOriginRect> Into<Rect> for &'a T {
fn into(self) -> Rect {
Rect {
x: self.center().x - self.width() / 2.0,
y: self.center().y - self.height() / 2.0,
w: self.width(),
h: self.height(),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment