teo_runtime/value/
range.rs1use std::fmt::{Display, Formatter};
2use serde::Serialize;
3use crate::value::Value;
4use teo_parser::value::range::Range as ParserRange;
5
6#[derive(Debug, Clone, PartialEq, Serialize)]
7pub struct Range {
8 pub closed: bool,
9 pub start: Box<Value>,
10 pub end: Box<Value>,
11}
12
13impl Range {
14
15 pub fn closed(&self) -> bool {
16 self.closed
17 }
18
19 pub fn start(&self) -> &Value {
20 self.start.as_ref()
21 }
22
23 pub fn end(&self) -> &Value {
24 self.end.as_ref()
25 }
26}
27
28impl Display for Range {
29
30 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31 Display::fmt(self.start.as_ref(), f)?;
32 if self.closed {
33 f.write_str("...")?;
34 } else {
35 f.write_str("..")?;
36 }
37 Display::fmt(self.end.as_ref(), f)
38 }
39}
40
41impl From<ParserRange> for Range {
42 fn from(value: ParserRange) -> Self {
43 Self {
44 closed: value.closed,
45 start: Box::new(value.start.as_ref().clone().into()),
46 end: Box::new(value.end.as_ref().clone().into()),
47 }
48 }
49}