From 33b8bc7724e7b1871c27c108820592c464535052 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Fri, 29 Oct 2021 12:15:26 -0400 Subject: [PATCH] [lib] Bespoke implement Debug for Pronoun --- src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6333f3d..baeca87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,7 +127,7 @@ impl Default for InstanceSettings { /// she/her or she/her/hers. /// /// Methods are provided to quickly generate these shorter forms, as well as example sentences. -#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[serde(from = "[String; 5]", into = "[String; 5]")] pub struct Pronoun { @@ -174,6 +174,31 @@ impl Pronoun { } } +impl fmt::Debug for Pronoun { + /// Pronouns are formatted with a vertical bar seperating forms + /// + /// ## Example + /// + /// ``` + /// # use pronouns_today::Pronoun; + /// let pronoun: Pronoun = ["she", "her", "her", "hers", "herself"].into(); + /// assert_eq!( + /// format!("{:?}", pronoun), + /// "Pronoun(she | her | her | hers | herself)" + /// ) + /// ``` + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, + "Pronoun({} | {} | {} | {} | {})", + self.subject_pronoun, + self.object_pronoun, + self.possesive_determiner, + self.possesive_pronoun, + self.reflexive_pronoun, + ) + } +} + impl fmt::Display for Pronoun { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.render_threeform())