Skip to content

Conversation

@nicoburns
Copy link
Collaborator

@nicoburns nicoburns commented Aug 1, 2025

Objective

Introduce an abstraction that allows "the whole of Taffy" to be generic over multiple types with only one generic parameter.

The core of this change is the introduction of:

/// Allows Taffy to abstract of the types it uses to represent strings and calc expressions.
/// In future it may be extended to abstract the scalar number type (currently f32)
pub trait Units {
    /// Trait that represents a cheaply clonable string. If you're unsure what to use here
    /// consider `Arc<str>` or `string_cache::Atom`.
    type Str: CheapCloneStr;

    /// Type representing a calc expression.
    /// If you're not using Calc then you can just use `()`
    type Calc: 'static;
}

pub struct DefaultUnits;
impl Units for DefaultUnits {
    type Str = String;
    type Calc = ();
}

Context

Feedback wanted

Is this a sensible change or am I going overboard with the generic types?

@nicoburns nicoburns added code quality Make the code cleaner or prettier. controversial This work requires a heightened standard of review due to implementation or design complexity labels Aug 1, 2025
type Calc: Calc;
}

/// A default implementation of the [`Units`] trait
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should note that it has no specific semantic value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "semantic value"?

Copy link
Collaborator

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. I think the semantics are clearer and I don't mind the added generics.

Signed-off-by: Nico Burns <nico@nicoburns.com>
Signed-off-by: Nico Burns <nico@nicoburns.com>
Signed-off-by: Nico Burns <nico@nicoburns.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Make the code cleaner or prettier. controversial This work requires a heightened standard of review due to implementation or design complexity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants