#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Deserialize,
serde::Serialize,
)]
#[serde(transparent)]
pub struct XsdNonNegativeInteger(u64);
#[derive(Clone, Debug, thiserror::Error)]
#[error("Error parsing NonNegativeInteger")]
pub struct XsdNonNegativeIntegerError;
impl XsdNonNegativeInteger {
pub fn to_u64(&self) -> u64 {
self.0
}
pub fn from_u64(u: u64) -> Self {
u.into()
}
}
impl AsRef<u64> for XsdNonNegativeInteger {
fn as_ref(&self) -> &u64 {
&self.0
}
}
impl From<XsdNonNegativeInteger> for u64 {
fn from(i: XsdNonNegativeInteger) -> Self {
i.0
}
}
impl From<u64> for XsdNonNegativeInteger {
fn from(f: u64) -> Self {
XsdNonNegativeInteger(f)
}
}
impl std::convert::TryFrom<String> for XsdNonNegativeInteger {
type Error = XsdNonNegativeIntegerError;
fn try_from(s: String) -> Result<Self, Self::Error> {
s.parse()
}
}
impl std::convert::TryFrom<&str> for XsdNonNegativeInteger {
type Error = XsdNonNegativeIntegerError;
fn try_from(s: &str) -> Result<Self, Self::Error> {
s.parse()
}
}
impl std::convert::TryFrom<&mut str> for XsdNonNegativeInteger {
type Error = XsdNonNegativeIntegerError;
fn try_from(s: &mut str) -> Result<Self, Self::Error> {
s.parse()
}
}
impl std::str::FromStr for XsdNonNegativeInteger {
type Err = XsdNonNegativeIntegerError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let f = s.parse().map_err(|_| XsdNonNegativeIntegerError)?;
Ok(XsdNonNegativeInteger(f))
}
}
impl std::fmt::Display for XsdNonNegativeInteger {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}