1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! A trait for structs that can build components.

use crate::model::Component;
use std::fmt::Debug;

/// Convert a variable id to a name.
/// Convenient for making consistent naming for variables
/// and constraints when automatically generating them.
pub fn vname(vid: usize) -> String {
    format!("var{}", vid)
}

/// Convert a constraint id to a name.
/// Convenient for making consistent naming for variables
/// and constraints when automatically generating them.
pub fn cname(cid: usize) -> String {
    format!("c{}", cid)
}

/// A trait for structs that can build components of a specified size.
/// This is used for creating components in benchmarks.
pub trait ComponentFactory {
    /// Returns the name of this factory.
    fn name() -> &'static str;
    /// Build the component with the specified name and number of constraints.
    fn build<T>(n_constraints: usize) -> Component<T>
    where
        T: Clone + Debug + Default + 'static;
}