ndarray-vision
ndarray-vision copied to clipboard
Added serde support for `Image` type
Resolves #54.
A feature flag still needs to be added, but I wanted to share what I have so far to make sure I am on the right track.
I am not sure if this is a good implementation because I have added (de)serialization of the colour model as a string but during deserialization is actually never used. The colour model must be known ahead of time and used for the type annotation. The type is not determined from the "model"
field. See the unit test for some context.
#[test]
fn deserialize_image_base() {
const EXPECTED: &str = r#"{"data":{"v":1,"dim":[2,3,3],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"model":"RGB"}"#;
let actual: Image<u8, RGB> = serde_json::from_str(EXPECTED).expect("Deserialized image");
assert_eq!(actual.model, PhantomData);
}
If the model is not RGB
then an error occurs instead of creating an image based on the colour model that is specified, but maybe this is correct way to do this? This is my first time really diving into manually implementing (de)serialization. Is there a way to deserialize into a "generic" Image.