ligen_ir/function/parameter/
mod.rs1#[cfg(any(test, feature = "mocks"))]
4pub mod mock;
5
6use std::fmt::{Display, Formatter};
7
8use crate::{prelude::*, Literal};
9use crate::{Identifier, Type, Attributes, Mutability};
10
11#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
12pub struct Parameter {
14 pub attributes: Attributes,
16 pub identifier: Identifier,
18 pub type_: Type,
20 pub default_value: Option<Literal>,
22}
23
24impl Parameter {
25 pub fn mutability(&self) -> Mutability {
27 if self.type_.is_mutable_reference() {
28 Mutability::Mutable
29 } else {
30 Mutability::Constant
31 }
32 }
33}
34
35impl Display for Parameter {
36 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
37 let attributes = if self.attributes.is_empty() { "".into() } else { format!(" {}", self.attributes) };
38 f.write_str(&format!("{}: {}{}", self.identifier, self.type_, attributes))
39 }
40}