Skip to main content

oxilean_codegen/ruby_backend/
rubyrescueblock_traits.rs

1//! # RubyRescueBlock - Trait Implementations
2//!
3//! This module contains trait implementations for `RubyRescueBlock`.
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::{fmt_ruby_class, fmt_ruby_method, fmt_ruby_module_stmt, fmt_ruby_stmt};
14use super::types::RubyRescueBlock;
15use std::fmt;
16
17impl std::fmt::Display for RubyRescueBlock {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        writeln!(f, "begin")?;
20        writeln!(f, "  {}", self.body)?;
21        for (types, var, body) in &self.rescues {
22            let types_str = if types.is_empty() {
23                String::new()
24            } else {
25                format!(" {}", types.join(", "))
26            };
27            let var_str = if let Some(v) = var {
28                format!(" => {}", v)
29            } else {
30                String::new()
31            };
32            writeln!(f, "rescue{}{}", types_str, var_str)?;
33            writeln!(f, "  {}", body)?;
34        }
35        if let Some(ens) = &self.ensure {
36            writeln!(f, "ensure")?;
37            writeln!(f, "  {}", ens)?;
38        }
39        write!(f, "end")
40    }
41}