1use alloc::borrow::Cow;
2use ownable::IntoOwned;
3use serde::Deserialize;
4
5use crate::buffer::BufferView;
6use crate::{Extensions, Extras, Idx};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum MimeTypeEnum {
11 Jpeg,
12 Png,
13}
14
15#[derive(Clone, PartialEq, Eq, Deserialize, IntoOwned)]
17#[serde(transparent)]
18pub struct MimeType<'a>(#[serde(borrow)] pub Cow<'a, str>);
19
20impl core::fmt::Debug for MimeType<'_> {
21 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22 if let Some(e) = self.to_enum() {
23 e.fmt(f)
24 } else {
25 self.0.fmt(f)
26 }
27 }
28}
29
30impl MimeType<'_> {
31 pub const JPEG: Self = Self(Cow::Borrowed("image/jpeg"));
32 pub const PNG: Self = Self(Cow::Borrowed("image/png"));
33
34 pub fn to_enum(&self) -> Option<MimeTypeEnum> {
35 if *self == Self::JPEG {
36 return Some(MimeTypeEnum::Jpeg);
37 } else if *self == Self::PNG {
38 return Some(MimeTypeEnum::Png);
39 }
40
41 None
42 }
43}
44
45#[derive(Debug, Clone, Deserialize, IntoOwned)]
47pub struct Image<'a> {
48 #[serde(borrow)]
50 pub name: Option<Cow<'a, str>>,
51
52 #[serde(borrow)]
54 pub uri: Option<Cow<'a, str>>,
55 #[serde(rename = "bufferView")]
57 pub buffer_view: Option<Idx<BufferView<'static>>>,
58 #[serde(borrow)]
60 pub mime_type: Option<MimeType<'a>>,
61
62 #[serde(borrow)]
63 pub extensions: Option<Extensions<'a>>,
64 #[serde(borrow)]
65 pub extras: Option<Extras<'a>>,
66}