use assert_struct::Like;
use toasty_core::stmt::{Expr, Value, ValueStream};
#[derive(Debug, Clone)]
pub struct Any;
impl Like<Any> for Expr {
fn like(&self, _pattern: &Any) -> bool {
true }
}
impl PartialEq<Any> for Expr {
fn eq(&self, _: &Any) -> bool {
true
}
}
impl Like<Any> for Value {
fn like(&self, _pattern: &Any) -> bool {
true }
}
impl PartialEq<Any> for Value {
fn eq(&self, _: &Any) -> bool {
true
}
}
pub enum ArgOr<V> {
Arg(usize),
Value(V),
}
impl<V> Like<ArgOr<V>> for Expr
where
Expr: Like<V>,
{
fn like(&self, pattern: &ArgOr<V>) -> bool {
match pattern {
ArgOr::Arg(pos) => matches!(self, Expr::Arg(arg) if arg.position == *pos),
ArgOr::Value(v) => self.like(v),
}
}
}
pub trait ValueStreamExt {
fn buffered(&self) -> Vec<Value>;
}
impl ValueStreamExt for ValueStream {
fn buffered(&self) -> Vec<Value> {
assert!(
self.is_buffered(),
"ValueStream is not fully buffered - call .buffer().await first"
);
self.buffered_to_vec()
}
}