use std::{fmt, convert::{TryFrom, TryInto}};
use crate::{Size, NCurseswWinError};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FieldInfo {
size: Size,
max: u16
}
impl FieldInfo {
pub fn new(size: Size, max: u16) -> Self {
Self { size, max }
}
pub fn size(self) -> Size {
self.size
}
pub fn max(self) -> u16 {
self.max
}
}
impl TryInto<ncursesw::form::FieldInfo> for FieldInfo {
type Error = NCurseswWinError;
fn try_into(self) -> Result<ncursesw::form::FieldInfo, Self::Error> {
Ok(ncursesw::form::FieldInfo::new(self.size().try_into()?, u16::try_into(self.max)?))
}
}
impl TryFrom<ncursesw::form::FieldInfo> for FieldInfo {
type Error = NCurseswWinError;
fn try_from(info: ncursesw::form::FieldInfo) -> Result<Self, Self::Error> {
Ok(Self { size: info.size().try_into()?, max: u16::try_from(info.max())? })
}
}
impl fmt::Display for FieldInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "(size: {}, max: {})", self.size, self.max)
}
}