use std::{convert::{From, Into}, ops::{BitOr, BitXor}};
use form::FormOption;
use shims::constants;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FormOptions {
raw: i32
}
impl FormOptions {
option_getter!(is_newline_overload, O_NL_OVERLOAD);
option_setter!(set_newline_overload, O_NL_OVERLOAD);
option_getter!(is_backspace_overload, O_BS_OVERLOAD);
option_setter!(set_backspace_overload, O_BS_OVERLOAD);
}
impl Default for FormOptions {
fn default() -> Self {
Self { raw: 0 }
}
}
impl BitOr for FormOptions {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self { raw: self.raw | rhs.raw }
}
}
impl BitXor for FormOptions {
type Output = Self;
fn bitxor(self, rhs: Self) -> Self::Output {
Self { raw: self.raw ^ rhs.raw }
}
}
impl BitOr<FormOption> for FormOptions {
type Output = Self;
fn bitor(mut self, rhs: FormOption) -> Self::Output {
match rhs {
FormOption::NewlineOverload => self.set_newline_overload(true),
FormOption::BackspaceOverload => self.set_backspace_overload(true)
}
self
}
}
impl BitXor<FormOption> for FormOptions {
type Output = Self;
fn bitxor(mut self, rhs: FormOption) -> Self::Output {
match rhs {
FormOption::NewlineOverload => self.set_newline_overload(false),
FormOption::BackspaceOverload => self.set_backspace_overload(false)
}
self
}
}
impl From<FormOption> for FormOptions {
fn from(form_option: FormOption) -> Self {
Self::default() | form_option
}
}
impl From<i32> for FormOptions {
fn from(raw: i32) -> Self {
Self { raw }
}
}
impl Into<i32> for FormOptions {
fn into(self) -> i32 {
self.raw
}
}