use seahash::SeaHasher; use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; #[derive(Clone, Debug, Eq, PartialEq)] pub struct ClipboardItem { pub(crate) text: String, pub(crate) metadata: Option, } impl ClipboardItem { pub fn new(text: String) -> Self { Self { text, metadata: None, } } pub fn with_metadata(mut self, metadata: T) -> Self { self.metadata = Some(serde_json::to_string(&metadata).unwrap()); self } pub fn text(&self) -> &String { &self.text } pub fn metadata(&self) -> Option where T: for<'a> Deserialize<'a>, { self.metadata .as_ref() .and_then(|m| serde_json::from_str(m).ok()) } pub(crate) fn text_hash(text: &str) -> u64 { let mut hasher = SeaHasher::new(); text.hash(&mut hasher); hasher.finish() } }