Lines
0 %
Functions
use std::fmt::Display;
use itertools::Itertools as _;
use polyquine::Quine;
use serde::{Deserialize, Serialize};
use ustr::Ustr;
/// A reference to an object stored in the [`SymbolTable`].
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize, Quine)]
#[path_prefix(conjure_cp::ast)]
pub enum Name {
/// A name given in the input model.
User(Ustr),
/// A name generated by Conjure-Oxide.
Machine(i32),
/// An auxiliary variable which is part of a Representation of a larger one.
/// See [crate::representation::Representation]
Represented(
// box these fields to make the size of name smaller
// this in turn makes the size of atom, expression, domain, ... smaller
Box<(
// The source variable
Name,
// The representation rule used
Ustr,
// Additional, rule dependent, information
)>,
),
/// A variable divided into several auxiliary ones through a Representation.
WithRepresentation(
Box<Name>,
/// representations chosen
Vec<Ustr>,
}
impl Name {
/// Creates a new `Name::User` from a `&str`.
pub fn user(name: &str) -> Self {
Name::User(Ustr::from(name))
impl Default for Name {
fn default() -> Self {
Name::User(Ustr::from(""))
uniplate::derive_unplateable!(Name);
impl Display for Name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Name::User(s) => write!(f, "{s}"),
Name::Machine(i) => write!(f, "__{i}"),
Name::Represented(fields) => {
let (name, rule_string, suffix) = fields.as_ref();
write!(f, "{name}#{rule_string}_{suffix}")
Name::WithRepresentation(name, items) => {
// TODO: what is the correct syntax for nested reprs?
write!(f, "{name}#{}", items.iter().join("#"))
impl From<&str> for Name {
fn from(s: &str) -> Self {
Name::User(Ustr::from(s))
impl From<i32> for Name {
fn from(i: i32) -> Self {
Name::Machine(i)