use std::fmt;
use crate::form::{FieldType, FIELDTYPE_INTEGER, IsFieldType};
#[derive(PartialEq, Eq, Hash)]
pub struct Integer<'a> {
fieldtype: &'a FieldType,
arguments: u8,
padding: i32,
minimum: libc::c_long,
maximum: libc::c_long
}
impl<'a> Integer<'a> {
pub fn new(padding: i32, minimum: libc::c_long, maximum: libc::c_long) -> Self {
Self { fieldtype: &*FIELDTYPE_INTEGER, arguments: 3, padding, minimum, maximum }
}
}
impl<'a> IsFieldType<'a, i32, libc::c_long, libc::c_long> for Integer<'a> {
fn fieldtype(&self) -> &'a FieldType {
self.fieldtype
}
fn arguments(&self) -> u8 {
self.arguments
}
fn arg1(&self) -> i32 {
self.padding
}
fn arg2(&self) -> libc::c_long {
self.minimum
}
fn arg3(&self) -> libc::c_long {
self.maximum
}
}
unsafe impl<'a> Send for Integer<'a> { } unsafe impl<'a> Sync for Integer<'a> { }
impl <'a>AsRef<Integer<'a>> for Integer<'a> {
fn as_ref(&self) -> &Self {
self
}
}
impl <'a>AsMut<Integer<'a>> for Integer<'a> {
fn as_mut(&mut self) -> &mut Self {
self
}
}
impl<'a> fmt::Debug for Integer<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{{ fieldtype: {:?}, arguments: {}, padding: {}, minimum: {}, maximum: {} }}",
self.fieldtype,
self.arguments,
self.padding,
self.minimum,
self.maximum
)
}
}