From 363fbc6e98f832471a17a10ec18e8823df6a2ed5 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 16 Apr 2026 21:31:57 +0800 Subject: Initialize Rust project with billing calculation functionality --- src/who.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/who.rs (limited to 'src/who.rs') diff --git a/src/who.rs b/src/who.rs new file mode 100644 index 0000000..9d6e5b5 --- /dev/null +++ b/src/who.rs @@ -0,0 +1,44 @@ +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Who { + name: String, +} + +impl std::ops::Deref for Who { + type Target = String; + + fn deref(&self) -> &Self::Target { + &self.name + } +} + +impl std::ops::DerefMut for Who { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.name + } +} + +impl From for Who { + fn from(s: String) -> Self { + Who { name: s } + } +} + +impl From<&str> for Who { + fn from(s: &str) -> Self { + Who { + name: s.to_string(), + } + } +} + +impl Into for Who { + fn into(self) -> String { + self.name + } +} + +impl std::fmt::Display for Who { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.name) + } +} -- cgit