Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl attribute matching #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat: impl attribute matching #5

wants to merge 1 commit into from

Conversation

huanghongxun
Copy link
Contributor

No description provided.

@huanghongxun huanghongxun requested a review from TtTRz December 27, 2024 13:16
@LastLeaf
Copy link
Member

Is it required to add an extra type parameter?

Copy link
Member

@TtTRz TtTRz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR!
But you still need to add some test cases.

@TtTRz TtTRz requested a review from LastLeaf December 30, 2024 08:29
@huanghongxun
Copy link
Contributor Author

huanghongxun commented Dec 30, 2024

Is it required to add an extra type parameter?

A type parameter allows embedder making its own attribute memory layout. Actually I also wishes making StyleQuery::classes generic too.

For example, my embedder setup an Attribute struct with attribute name enumerations to reduce memory footprint.

struct Attr {
   name: AttrName,
   value: TmplNativeData,
}

enum AttrName {
    Class,
    Name,
    EnableFlex,
    ...
}

TtTRz

This comment was marked as outdated.

@TtTRz TtTRz self-requested a review December 30, 2024 11:07
Copy link
Member

@TtTRz TtTRz left a comment

Choose a reason for hiding this comment

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

LGTM

@TtTRz TtTRz added the enhancement New feature or request label Dec 30, 2024
@LastLeaf
Copy link
Member

Is it required to add an extra type parameter?

A type parameter allows embedder making its own attribute memory layout. Actually I also wishes making StyleQuery::classes generic too.

For example, my embedder setup an Attribute struct with attribute name enumerations to reduce memory footprint.

struct Attr {
   name: AttrName,
   value: TmplNativeData,
}

enum AttrName {
    Class,
    Name,
    EnableFlex,
    ...
}

I think a default implementation is needed for the new type parameter, otherwise it can be weird for clients that does not need attribute matching.

@LastLeaf
Copy link
Member

And also, if you wish to use custom layout for node trees, it should better be done through a custom StyleQuery type:

trait StyleQuery {
    type ClassIter: Iterator<Item = (String, Option<NonZeroUsize>)>;
    fn tag_name(&self) -> &str;
    fn classes(&self) -> Self::ClassIter;
    // ...
    fn attribute(&self, name: &str) -> &str;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants