1use alloc::{borrow::Cow, string::String};
11
12#[derive(Clone, Debug, Default, PartialEq, Eq)]
14pub struct IcalBoolean<'a>(pub Cow<'a, str>);
15
16impl IcalBoolean<'_> {
17 pub fn is_true(&self) -> bool {
19 self.0.eq_ignore_ascii_case("TRUE")
20 }
21}
22
23impl<'a> From<&'a str> for IcalBoolean<'a> {
24 fn from(value: &'a str) -> Self {
25 Self(Cow::Borrowed(value))
26 }
27}
28
29impl From<String> for IcalBoolean<'_> {
30 fn from(value: String) -> Self {
31 Self(Cow::Owned(value))
32 }
33}
34
35impl<'a> From<Cow<'a, str>> for IcalBoolean<'a> {
36 fn from(value: Cow<'a, str>) -> Self {
37 Self(value)
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use crate::value::boolean::IcalBoolean;
44
45 #[test]
46 fn is_true_reads_both_cases() {
47 assert!(IcalBoolean::from("TRUE").is_true());
48 assert!(IcalBoolean::from("true").is_true());
49 assert!(!IcalBoolean::from("FALSE").is_true());
50 assert!(!IcalBoolean::from("false").is_true());
51 }
52}