mirror of
https://github.com/nushell/nushell
synced 2025-01-25 11:25:21 +00:00
44 lines
735 B
Rust
44 lines
735 B
Rust
use std::ops::{Index, IndexMut};
|
|
|
|
use super::Statement;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Block {
|
|
pub stmts: Vec<Statement>,
|
|
}
|
|
|
|
impl Block {
|
|
pub fn len(&self) -> usize {
|
|
self.stmts.len()
|
|
}
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
self.stmts.is_empty()
|
|
}
|
|
}
|
|
|
|
impl Index<usize> for Block {
|
|
type Output = Statement;
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
|
&self.stmts[index]
|
|
}
|
|
}
|
|
|
|
impl IndexMut<usize> for Block {
|
|
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
|
&mut self.stmts[index]
|
|
}
|
|
}
|
|
|
|
impl Default for Block {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl Block {
|
|
pub fn new() -> Self {
|
|
Self { stmts: vec![] }
|
|
}
|
|
}
|