1
0
dust/src/value/function.rs

39 lines
896 B
Rust
Raw Normal View History

2023-08-22 15:40:50 +00:00
use std::fmt::{self, Display, Formatter};
use serde::{Deserialize, Serialize};
2023-10-06 17:32:58 +00:00
use crate::{Identifier, Statement};
2023-08-22 15:40:50 +00:00
2023-09-30 21:52:37 +00:00
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Function {
2023-10-01 09:03:59 +00:00
identifiers: Vec<Identifier>,
2023-09-30 21:52:37 +00:00
statements: Vec<Statement>,
}
2023-08-22 15:40:50 +00:00
impl Function {
2023-10-01 09:03:59 +00:00
pub fn new(identifiers: Vec<Identifier>, statements: Vec<Statement>) -> Self {
2023-09-30 21:52:37 +00:00
Function {
identifiers,
statements,
}
2023-08-22 15:40:50 +00:00
}
2023-10-06 21:11:50 +00:00
pub fn identifiers(&self) -> &Vec<Identifier> {
&self.identifiers
}
pub fn statements(&self) -> &Vec<Statement> {
&self.statements
}
}
2023-08-22 15:40:50 +00:00
impl Display for Function {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
2023-09-30 21:52:37 +00:00
write!(
f,
2023-10-06 17:32:58 +00:00
"function < {:?} > {{ {:?} }}", // TODO: Correct this output
2023-09-30 21:52:37 +00:00
self.identifiers, self.statements
)
2023-08-22 15:40:50 +00:00
}
}