bql 0.1.0

BQL — Bridge Query Language parser and formatter (Rust, generated).
Documentation
//! Generated owned-conversion methods. Do not edit by hand.
//!
//! `parse` yields a tree that borrows from its input (`Cow::Borrowed`).
//! Each node's `into_owned` deep-clones every borrowed string into an
//! owned `String`, producing a `'static` tree that can outlive the input.

use std::borrow::Cow;

use crate::ast::*;

impl<'a> And<'a> {
    /// Consume this borrowed `And`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `Between`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `Compare`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `Empty`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    pub fn into_owned(self) -> Empty<'static> {
        Empty {
            field: Cow::Owned(self.field.into_owned()),
        }
    }
}

impl<'a> Expr<'a> {
    /// Consume this borrowed `Expr`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `In`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `Or`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `Participant`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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> {
    /// Consume this borrowed `Value`, deep-cloning every borrowed string
    /// into owned storage so the result no longer borrows the input.
    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),
        }
    }
}