use std::borrow::Cow;
use crate::ast::*;
impl<'a> And<'a> {
pub fn into_owned(self) -> And<'static> {
And {
operands: self
.operands
.into_iter()
.map(|x| Box::new((*x).into_owned()))
.collect(),
}
}
}
impl<'a> Between<'a> {
pub fn into_owned(self) -> Between<'static> {
Between {
field: Cow::Owned(self.field.into_owned()),
lo: self.lo.into_owned(),
hi: self.hi.into_owned(),
}
}
}
impl<'a> Compare<'a> {
pub fn into_owned(self) -> Compare<'static> {
Compare {
field: Cow::Owned(self.field.into_owned()),
op: self.op,
value: self.value.into_owned(),
}
}
}
impl<'a> Empty<'a> {
pub fn into_owned(self) -> Empty<'static> {
Empty {
field: Cow::Owned(self.field.into_owned()),
}
}
}
impl<'a> Expr<'a> {
pub fn into_owned(self) -> Expr<'static> {
match self {
Expr::And(x) => Expr::And(Box::new((*x).into_owned())),
Expr::Or(x) => Expr::Or(Box::new((*x).into_owned())),
Expr::Not(x) => Expr::Not(Box::new((*x).into_owned())),
Expr::Compare(x) => Expr::Compare(x.into_owned()),
Expr::Between(x) => Expr::Between(x.into_owned()),
Expr::NotBetween(x) => Expr::NotBetween(x.into_owned()),
Expr::In(x) => Expr::In(x.into_owned()),
Expr::NotIn(x) => Expr::NotIn(x.into_owned()),
Expr::IsEmpty(x) => Expr::IsEmpty(x.into_owned()),
Expr::IsNull(x) => Expr::IsNull(x.into_owned()),
Expr::IsNotEmpty(x) => Expr::IsNotEmpty(x.into_owned()),
Expr::IsNotNull(x) => Expr::IsNotNull(x.into_owned()),
}
}
}
impl<'a> In<'a> {
pub fn into_owned(self) -> In<'static> {
In {
field: Cow::Owned(self.field.into_owned()),
values: self.values.into_iter().map(|x| x.into_owned()).collect(),
}
}
}
impl<'a> Or<'a> {
pub fn into_owned(self) -> Or<'static> {
Or {
operands: self
.operands
.into_iter()
.map(|x| Box::new((*x).into_owned()))
.collect(),
}
}
}
impl<'a> Participant<'a> {
pub fn into_owned(self) -> Participant<'static> {
Participant {
r#type: Cow::Owned(self.r#type.into_owned()),
id: Cow::Owned(self.id.into_owned()),
}
}
}
impl<'a> Value<'a> {
pub fn into_owned(self) -> Value<'static> {
match self {
Value::String(x) => Value::String(Cow::Owned(x.into_owned())),
Value::Enum(x) => Value::Enum(Cow::Owned(x.into_owned())),
Value::Integer(x) => Value::Integer(Cow::Owned(x.into_owned())),
Value::Float(x) => Value::Float(Cow::Owned(x.into_owned())),
Value::Boolean(x) => Value::Boolean(x),
Value::Date(x) => Value::Date(Cow::Owned(x.into_owned())),
Value::DateTime(x) => Value::DateTime(Cow::Owned(x.into_owned())),
Value::Participant(x) => Value::Participant(x.into_owned()),
Value::Now(x) => Value::Now(x),
}
}
}