use std::fmt::{self, Display, Formatter};
use amplify::Wrapper;
#[derive(Wrapper, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From, Default)]
#[derive(NetworkEncode, NetworkDecode)]
pub struct OptionDetails(pub Option<String>);
impl Display for OptionDetails {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self.as_inner() {
None => Ok(()),
Some(msg) => write!(f, "; \"{}\"", msg),
}
}
}
impl OptionDetails {
pub fn with(s: impl ToString) -> Self { Self(Some(s.to_string())) }
pub fn new() -> Self { Self(None) }
pub fn none() -> Self { Self(None) }
}
impl From<String> for OptionDetails {
fn from(s: String) -> Self { OptionDetails(Some(s)) }
}
impl From<&str> for OptionDetails {
fn from(s: &str) -> Self { OptionDetails(Some(s.to_string())) }
}