use serde::{Deserialize, Serialize};
use crate::error::DomainError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(try_from = "u16", into = "u16")]
pub struct ChildQuorum(u16);
impl ChildQuorum {
pub fn new(value: u16) -> Result<Self, DomainError> {
if value == 0 {
return Err(DomainError::MustBeNonZero {
field: "child_quorum",
});
}
Ok(Self(value))
}
#[must_use]
pub const fn get(self) -> u16 {
self.0
}
}
impl TryFrom<u16> for ChildQuorum {
type Error = DomainError;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::new(value)
}
}
impl From<ChildQuorum> for u16 {
fn from(value: ChildQuorum) -> Self {
value.0
}
}