Remove unused Index(Mut) impls on AST types (#11903)

# Description
Both `Block` and `Pipeline` had `Index`/`IndexMut` implementations to
access their elements, that are currently unused.
Explicit helpers or iteration would generally be preferred anyways but
in the current state the inner containers are `pub` and are liberally
used. (Sometimes with potentially panicking indexing or also iteration)

As it is potentially unclear what the meaning of the element from a
block or pipeline queried by a usize is, let's remove it entirely until
we come up with a better API.

# User-Facing Changes
None

Plugin authors shouldn't dig into AST internals
This commit is contained in:
Stefan Holderbach
2024-02-21 11:02:30 +01:00
committed by GitHub
parent b23fe30530
commit 6e590fe0a2
4 changed files with 66 additions and 96 deletions

View File

@ -1,7 +1,6 @@
use super::Pipeline;
use crate::{ast::PipelineElement, Signature, Span, Type, VarId};
use serde::{Deserialize, Serialize};
use std::ops::{Index, IndexMut};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Block {
@ -22,20 +21,6 @@ impl Block {
}
}
impl Index<usize> for Block {
type Output = Pipeline;
fn index(&self, index: usize) -> &Self::Output {
&self.pipelines[index]
}
}
impl IndexMut<usize> for Block {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.pipelines[index]
}
}
impl Default for Block {
fn default() -> Self {
Self::new()

View File

@ -1,6 +1,5 @@
use crate::{ast::Expression, engine::StateWorkingSet, Span};
use serde::{Deserialize, Serialize};
use std::ops::{Index, IndexMut};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub enum Redirection {
@ -159,17 +158,3 @@ impl Pipeline {
self.elements.is_empty()
}
}
impl Index<usize> for Pipeline {
type Output = PipelineElement;
fn index(&self, index: usize) -> &Self::Output {
&self.elements[index]
}
}
impl IndexMut<usize> for Pipeline {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.elements[index]
}
}