use std::{ fmt::{self, Debug}, ops::{Deref, DerefMut}, }; /// Wrapper type for values which may contain user input. /// /// Use this to prevent logging user input in production builds. In local development builds, the /// value will still be shown. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct UserInput(T); impl UserInput { pub fn new>(value: U) -> Self { Self(value.into()) } pub fn into_inner(self) -> T { self.0 } } impl Deref for UserInput { type Target = T; fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for UserInput { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl Debug for UserInput { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if cfg!(debug_assertions) { f.debug_tuple("UserInput").field(&self.0).finish() } else { f.debug_struct("UserInput").finish_non_exhaustive() } } }