#![allow(unused_imports)]
use std::fmt;
use unindent::{
unindent,
Unindent,
};
use std::hash::Hash;
use crate::_Object;
use crate::type_of;
#[derive(Copy)]
#[derive(Clone)]
pub struct Float<T: Sized> {
_float: T,
}
impl<T> Float<T>
where
T: Sized,
{
pub fn new(_float: T) -> Self {
Float {
_float,
}
}
}
impl<T> From<T> for Float<T>
where
T: Sized,
{
fn from(_float: T) -> Self {
Float {
_float,
}
}
}
impl Default for Float<f32> {
fn default() -> Self {
Float {
_float: 0.0f32
}
}
}
impl Default for Float<f64> {
fn default() -> Self {
Float {
_float: 0.0f64
}
}
}
impl<T> _Object for Float<T>
where
T: Sized + fmt::Display,
{
fn __repr__(&self) -> String {
format!("{}", self._float)
}
fn __str__(&self) -> String {
format!("{}", self._float)
}
}
impl<T> fmt::Display for Float<T>
where
T: Sized + fmt::Display,
{
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let _type = type_of(&self._float);
if formatter.alternate() {
write!(formatter, "{} -> <{}>", self._float, _type)
} else {
write!(formatter, "{}", self._float)
}
}
}
impl<T> fmt::Debug for Float<T>
where
T: Sized + fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let _type = type_of(&self._float);
if f.alternate() {
let _fmt = format!(
"Float<{}> {{
_float: {}
}}",
_type, self._float
);
let _fmt = _fmt.unindent();
write!(f, "{}", _fmt)
} else {
write!(
f,
"Float<{}> {{ _float: {} }}",
_type, self._float
)
}
}
}
impl<T> PartialEq<T> for Float<T>
where
T: Sized + std::cmp::PartialEq,
{
fn eq(&self, other: &T) -> bool {
self._float == *other
}
}