Skip to content

Commit

Permalink
refactor!: Seal InputIndicator trait
Browse files Browse the repository at this point in the history
The pubic trait `InputIndicator` used to be implementable downstream.
This was never intended. Now, by sealing the trait, downstream
dependencies cannot implement the trait.
  • Loading branch information
jan-ferdinand committed Sep 12, 2024
1 parent d4c48c5 commit b803e13
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion triton-constraint-circuit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ use quote::quote;
use quote::ToTokens;
use twenty_first::prelude::*;

mod private {
// A public but un-nameable type for sealing traits.
pub trait Seal {}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct DegreeLoweringInfo {
/// The degree after degree lowering. Must be greater than 1.
Expand Down Expand Up @@ -94,7 +99,10 @@ impl BinOp {
/// a uniform interface for accessing the index.
///
/// Having `Copy + Hash + Eq` helps to put `InputIndicator`s into containers.
pub trait InputIndicator: Debug + Display + Copy + Hash + Eq + ToTokens {
///
/// This is a _sealed_ trait. It is not intended (or possible) to implement this trait outside the
/// crate defining it.
pub trait InputIndicator: Debug + Display + Copy + Hash + Eq + ToTokens + private::Seal {
/// `true` iff `self` refers to a column in the base table.
fn is_main_table_column(&self) -> bool;

Expand Down Expand Up @@ -122,6 +130,8 @@ pub enum SingleRowIndicator {
Aux(usize),
}

impl private::Seal for SingleRowIndicator {}

impl Display for SingleRowIndicator {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let input_indicator: String = match self {
Expand Down Expand Up @@ -187,6 +197,8 @@ pub enum DualRowIndicator {
NextAux(usize),
}

impl private::Seal for DualRowIndicator {}

impl Display for DualRowIndicator {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let input_indicator: String = match self {
Expand Down

0 comments on commit b803e13

Please sign in to comment.