use crate::{unlock::UnlockIndex, Error};
#[derive(Clone, Debug, Eq, PartialEq, Hash, packable::Packable)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[packable(unpack_error = Error, with = Error::InvalidReferenceIndex)]
pub struct ReferenceUnlock(UnlockIndex);
impl TryFrom<u16> for ReferenceUnlock {
type Error = Error;
fn try_from(index: u16) -> Result<Self, Self::Error> {
Self::new(index)
}
}
impl ReferenceUnlock {
pub const KIND: u8 = 1;
#[inline(always)]
pub fn new(index: u16) -> Result<Self, Error> {
index.try_into().map(Self).map_err(Error::InvalidReferenceIndex)
}
#[inline(always)]
pub fn index(&self) -> u16 {
self.0.get()
}
}
#[cfg(feature = "dto")]
#[allow(missing_docs)]
pub mod dto {
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct ReferenceUnlockDto {
#[serde(rename = "type")]
pub kind: u8,
#[serde(rename = "reference")]
pub index: u16,
}
}