#[cfg(feature = "bitmatrix")]
mod matrix;
#[cfg(feature = "bitmatrix")]
pub use matrix::*;
#[cfg(test)]
mod tests;
#[cfg(feature = "derive")]
pub use onehot_derive::*;
pub trait OneHot {
const ONEHOT_LEN: usize;
type Labels: Iterator<Item = &'static str>;
type Encoder: Iterator<Item = bool>;
fn labels() -> Self::Labels;
fn onehot(&self) -> Self::Encoder;
}
impl<T: OneHot> OneHot for &T {
const ONEHOT_LEN: usize = T::ONEHOT_LEN;
type Labels = T::Labels;
type Encoder = T::Encoder;
fn labels() -> Self::Labels {
T::labels()
}
fn onehot(&self) -> Self::Encoder {
(**self).onehot()
}
}
impl<T: OneHot> OneHot for &mut T {
const ONEHOT_LEN: usize = T::ONEHOT_LEN;
type Labels = T::Labels;
type Encoder = T::Encoder;
fn labels() -> Self::Labels {
T::labels()
}
fn onehot(&self) -> Self::Encoder {
(**self).onehot()
}
}
impl OneHot for bool {
const ONEHOT_LEN: usize = 1;
type Labels = std::iter::Once<&'static str>;
type Encoder = std::iter::Once<bool>;
fn labels() -> Self::Labels {
std::iter::once("bool")
}
fn onehot(&self) -> Self::Encoder {
std::iter::once(*self)
}
}