1use serde::{
2 de::{self},
3 Deserialize, Serialize,
4};
5
6use crate::{objects::*, ChartExt};
7
8#[derive(Debug, Clone, Deserialize, Serialize, Default)]
9pub struct Doughnut {
10 #[serde(rename = "type")]
11 r#type: DoughnutString,
12 data: Dataset<Vec<SinglePointDataset>>,
13 options: ChartOptions,
14 id: String,
15}
16#[cfg(feature = "workers")]
17impl crate::WorkerChartExt for Doughnut {}
18impl ChartExt for Doughnut {
19 type DS = Dataset<Vec<SinglePointDataset>>;
20
21 fn get_id(&self) -> &str {
22 &self.id
23 }
24 fn id(mut self, id: String) -> Self {
25 self.id = id;
26 self
27 }
28
29 fn get_data(&mut self) -> &mut Self::DS {
30 &mut self.data
31 }
32
33 fn get_options(&mut self) -> &mut ChartOptions {
34 &mut self.options
35 }
36}
37
38#[derive(Debug, Default, Clone)]
39pub struct DoughnutString;
40impl<'de> Deserialize<'de> for DoughnutString {
41 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
42 where
43 D: serde::Deserializer<'de>,
44 {
45 match String::deserialize(deserializer)?.to_lowercase().as_str() {
46 "doughnut" => Ok(DoughnutString),
47 other => Err(de::Error::custom(format!(
48 "`{other}` is not a valid DoughnutString."
49 ))),
50 }
51 }
52}
53impl Serialize for DoughnutString {
54 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
55 where
56 S: serde::Serializer,
57 {
58 serializer.serialize_str("doughnut")
59 }
60}