use std::marker::PhantomData; pub struct RgbFormat; pub struct RgbaFormat; pub struct Image { pub data: Vec, pub width: usize, pub height: usize, format: PhantomData, } trait ComponentsCount { const COMPONENTS_COUNT: usize; } impl ComponentsCount for Image { const COMPONENTS_COUNT: usize = 3; } impl ComponentsCount for Image { const COMPONENTS_COUNT: usize = 4; } trait Test { fn get_components_count() -> usize; // fn get_pixel(&self, x: usize, y: usize) -> &[u8; Self::COMPONENTS_COUNT]; // fn set_pixel(&self, x: usize, y: usize, pixel: [u8; Self::COMPONENTS_COUNT]); } impl Test for T { fn get_components_count() -> usize { Self::COMPONENTS_COUNT } }