flowlog-build 0.3.3

Build-time FlowLog compiler for library mode.
Documentation
//! FnCall predicate signatures for FlowLog Datalog programs.

use crate::catalog::ArithmeticPos;
use std::fmt;

/// A fn_call predicate with variables resolved to their concrete positions.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub(crate) struct FnCallPredicatePos {
    name: String,
    args: Vec<ArithmeticPos>,
    is_negated: bool,
}

impl FnCallPredicatePos {
    /// Construct a new positional fn_call predicate.
    pub(crate) fn new(name: String, args: Vec<ArithmeticPos>, is_negated: bool) -> Self {
        Self {
            name,
            args,
            is_negated,
        }
    }

    /// Returns the function name.
    #[inline]
    pub(crate) fn name(&self) -> &str {
        &self.name
    }

    /// Returns the argument arithmetic positions.
    #[inline]
    pub(crate) fn args(&self) -> &[ArithmeticPos] {
        &self.args
    }

    /// Whether the UDF result is negated.
    #[inline]
    pub(crate) fn is_negated(&self) -> bool {
        self.is_negated
    }
}

impl fmt::Display for FnCallPredicatePos {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let args_str = self
            .args
            .iter()
            .map(ToString::to_string)
            .collect::<Vec<_>>()
            .join(", ");
        if self.is_negated {
            write!(f, "[!{}({})]", self.name, args_str)
        } else {
            write!(f, "[{}({})]", self.name, args_str)
        }
    }
}