use crate::types::Type;
use std::fmt::{Display, Formatter, Write};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Range {
    pub of: Box<Type>,
}

impl Range {
    pub fn new(of: Type) -> Range {
        Range { of: Box::new(of) }
    }

    pub fn fmt_indented(
        &self,
        f: &mut impl Write,
        indentation: usize,
        max_fields: usize,
    ) -> std::fmt::Result {
        write!(f, "range(")?;
        self.of.fmt_indented(f, indentation, max_fields)?;
        write!(f, ")")
    }
}

impl Display for Range {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        self.fmt_indented(f, 0, usize::MAX)
    }
}
