Skip to main content

oxilean_codegen/js_backend/
jsfunction_traits.rs

1//! # JsFunction - Trait Implementations
2//!
3//! This module contains trait implementations for `JsFunction`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use crate::lcnf::*;
12
13use super::functions::*;
14use super::types::JsFunction;
15use std::fmt;
16
17impl fmt::Display for JsFunction {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        if self.is_export {
20            write!(f, "export ")?;
21        }
22        if self.is_async {
23            write!(f, "async ")?;
24        }
25        write!(f, "function {}(", self.name)?;
26        for (i, p) in self.params.iter().enumerate() {
27            if i > 0 {
28                write!(f, ", ")?;
29            }
30            write!(f, "{}", p)?;
31        }
32        writeln!(f, ") {{")?;
33        let body_text = display_indented(&self.body, 2);
34        if !body_text.is_empty() {
35            writeln!(f, "{}", body_text)?;
36        }
37        write!(f, "}}")
38    }
39}