I'm trying to add support for embedded-graphics to my display driver crate.
I have the following code in my lib.rs
:
// lib.rs
pub struct ILI9486<CSX, RSX, IF> {
interface: IF,
chip_select: CSX,
reset: RSX,
}
I created a file graphics.rs
to add the implementation of the required trait DrawTarget
.
// graphics.rs
use embedded_graphics::DrawTarget;
impl DrawTarget for ILI9486 {}
With that code, the code compiles, even though I didn't implement draw_pixel()
or size()
. Why does it compile?
I would expect the compiler to complain. If I implement a trait without implementing a function the compiler complains:
pub trait MyTrait {
fn foo();
}
pub struct ILI9486<CSX, RSX, IF> {
interface: IF,
chip_select: CSX,
reset: RSX,
}
impl<CSX, RSX, IF> MyTrait for ILI9486<CSX, RSX, IF>
where
IF: WriteOnlyDataCommand,
CSX: OutputPin,
RSX: OutputPin,
{
}
which results in:
error[E0046]: not all trait items implemented, missing: `foo`
--> crates/ili9486-rs/src/lib.rs:16:1
|
7 | fn foo();
| --------- `foo` from trait
...
16 | / impl<CSX, RSX, IF> MyTrait for ILI9486<CSX, RSX, IF>
17 | | where
18 | | IF: WriteOnlyDataCommand,
19 | | CSX: OutputPin,
20 | | RSX: OutputPin,
21 | | {
22 | | }
| |_^ missing `foo` in implementation
So I am puzzled.