1
0
dust/src/value/function.rs

39 lines
869 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-31 17:04:22 +00:00
use crate::{Block, Identifier};
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-31 22:18:39 +00:00
parameters: Option<Vec<Identifier>>,
2023-10-31 17:04:22 +00:00
body: Box<Block>,
2023-09-30 21:52:37 +00:00
}
2023-08-22 15:40:50 +00:00
impl Function {
2023-10-31 22:18:39 +00:00
pub fn new(parameters: Option<Vec<Identifier>>, body: Block) -> Self {
2023-09-30 21:52:37 +00:00
Function {
2023-10-31 17:04:22 +00:00
parameters,
body: Box::new(body),
2023-09-30 21:52:37 +00:00
}
2023-08-22 15:40:50 +00:00
}
2023-10-06 21:11:50 +00:00
2023-10-31 22:18:39 +00:00
pub fn identifiers(&self) -> &Option<Vec<Identifier>> {
2023-10-07 16:37:35 +00:00
&self.parameters
2023-10-06 21:11:50 +00:00
}
2023-10-31 17:04:22 +00:00
pub fn body(&self) -> &Block {
2023-10-07 16:37:35 +00:00
&self.body
2023-10-06 21:11:50 +00:00
}
}
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-10-07 16:37:35 +00:00
self.parameters, self.body
2023-09-30 21:52:37 +00:00
)
2023-08-22 15:40:50 +00:00
}
}