mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-05 12:05:01 +00:00
99 lines
1.6 KiB
Rust
99 lines
1.6 KiB
Rust
|
use std::{
|
||
|
borrow::Borrow,
|
||
|
ops::{Deref, DerefMut},
|
||
|
};
|
||
|
|
||
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Deserialize, serde::Serialize)]
|
||
|
#[serde(transparent)]
|
||
|
pub struct Sensitive<T>(T);
|
||
|
|
||
|
impl<T> Sensitive<T> {
|
||
|
pub fn new(item: T) -> Self {
|
||
|
Sensitive(item)
|
||
|
}
|
||
|
|
||
|
pub fn into_inner(this: Self) -> T {
|
||
|
this.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T> std::fmt::Debug for Sensitive<T> {
|
||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
f.debug_struct("Sensitive").finish()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T> AsRef<T> for Sensitive<T> {
|
||
|
fn as_ref(&self) -> &T {
|
||
|
&self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl AsRef<str> for Sensitive<String> {
|
||
|
fn as_ref(&self) -> &str {
|
||
|
&self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl AsRef<[u8]> for Sensitive<String> {
|
||
|
fn as_ref(&self) -> &[u8] {
|
||
|
self.0.as_ref()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl AsRef<[u8]> for Sensitive<Vec<u8>> {
|
||
|
fn as_ref(&self) -> &[u8] {
|
||
|
self.0.as_ref()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T> AsMut<T> for Sensitive<T> {
|
||
|
fn as_mut(&mut self) -> &mut T {
|
||
|
&mut self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl AsMut<str> for Sensitive<String> {
|
||
|
fn as_mut(&mut self) -> &mut str {
|
||
|
&mut self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Deref for Sensitive<String> {
|
||
|
type Target = str;
|
||
|
|
||
|
fn deref(&self) -> &Self::Target {
|
||
|
&self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl DerefMut for Sensitive<String> {
|
||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||
|
&mut self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T> From<T> for Sensitive<T> {
|
||
|
fn from(t: T) -> Self {
|
||
|
Sensitive(t)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<&str> for Sensitive<String> {
|
||
|
fn from(s: &str) -> Self {
|
||
|
Sensitive(s.into())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<T> Borrow<T> for Sensitive<T> {
|
||
|
fn borrow(&self) -> &T {
|
||
|
&self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Borrow<str> for Sensitive<String> {
|
||
|
fn borrow(&self) -> &str {
|
||
|
&self.0
|
||
|
}
|
||
|
}
|