2021-09-02 10:25:22 +02:00
|
|
|
use std::ops::{Index, IndexMut};
|
|
|
|
|
2022-01-30 23:05:25 +01:00
|
|
|
use crate::{Signature, Span, VarId};
|
2021-09-06 01:16:27 +02:00
|
|
|
|
2022-02-15 20:31:14 +01:00
|
|
|
use super::Pipeline;
|
2021-09-02 10:25:22 +02:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Block {
|
2021-09-06 01:16:27 +02:00
|
|
|
pub signature: Box<Signature>,
|
2022-02-15 20:31:14 +01:00
|
|
|
pub pipelines: Vec<Pipeline>,
|
2021-10-25 22:04:23 +02:00
|
|
|
pub captures: Vec<VarId>,
|
2022-01-29 21:45:46 +01:00
|
|
|
pub redirect_env: bool,
|
2022-01-30 23:05:25 +01:00
|
|
|
pub span: Option<Span>, // None option encodes no span to avoid using test_span()
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Block {
|
|
|
|
pub fn len(&self) -> usize {
|
2022-02-15 20:31:14 +01:00
|
|
|
self.pipelines.len()
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
2022-02-15 20:31:14 +01:00
|
|
|
self.pipelines.is_empty()
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Index<usize> for Block {
|
2022-02-15 20:31:14 +01:00
|
|
|
type Output = Pipeline;
|
2021-09-02 10:25:22 +02:00
|
|
|
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
2022-02-15 20:31:14 +01:00
|
|
|
&self.pipelines[index]
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IndexMut<usize> for Block {
|
|
|
|
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
2022-02-15 20:31:14 +01:00
|
|
|
&mut self.pipelines[index]
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Block {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Block {
|
|
|
|
pub fn new() -> Self {
|
2021-09-06 01:16:27 +02:00
|
|
|
Self {
|
|
|
|
signature: Box::new(Signature::new("")),
|
2022-02-15 20:31:14 +01:00
|
|
|
pipelines: vec![],
|
2021-10-25 22:04:23 +02:00
|
|
|
captures: vec![],
|
2022-01-29 21:45:46 +01:00
|
|
|
redirect_env: false,
|
2022-01-30 23:05:25 +01:00
|
|
|
span: None,
|
2021-09-26 14:00:03 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-02 10:25:22 +02:00
|
|
|
}
|
2021-09-10 09:28:43 +02:00
|
|
|
|
|
|
|
impl<T> From<T> for Block
|
|
|
|
where
|
2022-02-15 20:31:14 +01:00
|
|
|
T: Iterator<Item = Pipeline>,
|
2021-09-10 09:28:43 +02:00
|
|
|
{
|
2022-02-15 20:31:14 +01:00
|
|
|
fn from(pipelines: T) -> Self {
|
2021-09-10 09:28:43 +02:00
|
|
|
Self {
|
|
|
|
signature: Box::new(Signature::new("")),
|
2022-02-15 20:31:14 +01:00
|
|
|
pipelines: pipelines.collect(),
|
2021-10-25 22:04:23 +02:00
|
|
|
captures: vec![],
|
2022-01-29 21:45:46 +01:00
|
|
|
redirect_env: false,
|
2022-01-30 23:05:25 +01:00
|
|
|
span: None,
|
2021-09-10 09:28:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|