use core::fmt::{self, Write};
use crate::operand::Operand;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct In {
pub(crate) op: Operand,
pub(crate) items: Vec<Operand>,
}
impl In {
pub fn new<O, I, T>(op: O, items: I) -> Self
where
O: Into<Operand>,
I: IntoIterator<Item = T>,
T: Into<Operand>,
{
Self {
op: op.into(),
items: items.into_iter().map(Into::into).collect(),
}
}
}
impl fmt::Display for In {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.op.fmt(f)?;
f.write_str(" IN (")?;
let mut first = true;
self.items.iter().try_for_each(|item| {
if first {
first = false;
} else {
f.write_char(',')?;
}
item.fmt(f)
})?;
f.write_char(')')
}
}