1use crate::{Tldr, TldrContext, TldrResult, ToTldr};
4use alloc::{boxed::Box, string::String};
5use core::fmt::Debug;
6
7#[derive(Clone, Debug, Default)]
28#[cfg_attr(feature = "builder", derive(bon::Builder))]
29#[cfg_attr(feature = "builder", builder(on(T, into)))]
30#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
31#[cfg_attr(feature = "serde", serde(default))]
32pub struct TldrSummary<T: Clone + Debug + Default = String> {
33 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
37 pub who: Option<T>,
38
39 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
43 pub what: Option<T>,
44
45 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
49 pub when: Option<T>,
50
51 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
55 pub r#where: Option<T>,
56
57 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
61 pub why: Option<T>,
62
63 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
67 pub whence: Option<T>,
68
69 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
73 pub how: Option<T>,
74}
75
76impl<T: Clone + Debug + Default + 'static> ToTldr<T> for TldrSummary<T> {
77 type Error = ();
78
79 fn to_tldr(&self) -> Box<dyn Tldr<T, Error = Self::Error>> {
80 Box::new(self.clone())
81 }
82}
83
84impl<T: Clone + Debug + Default> Tldr<T> for TldrSummary<T> {
85 type Error = ();
86
87 fn who(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
88 Ok(self.who.clone())
89 }
90
91 fn what(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
92 Ok(self.what.clone())
93 }
94
95 fn when(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
96 Ok(self.when.clone())
97 }
98
99 fn r#where(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
100 Ok(self.r#where.clone())
101 }
102
103 fn why(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
104 Ok(self.why.clone())
105 }
106
107 fn whence(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
108 Ok(self.whence.clone())
109 }
110
111 fn how(&self, _ctx: &TldrContext) -> TldrResult<T, Self::Error> {
112 Ok(self.how.clone())
113 }
114}