Skip to content

Commit

Permalink
Use Box<str> in AST
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Dec 4, 2024
1 parent 2dd490e commit 9b00da5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/selectors_vm/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ impl NthChild {
pub(crate) enum OnTagNameExpr {
ExplicitAny,
Unmatchable,
LocalName(String),
LocalName(Box<str>),
NthChild(NthChild),
NthOfType(NthChild),
}

#[derive(Eq, PartialEq)]
pub(crate) struct AttributeComparisonExpr {
pub name: String,
pub value: String,
pub name: Box<str>,
pub value: Box<str>,
pub case_sensitivity: ParsedCaseSensitivity,
pub operator: AttrSelectorOperator,
}
Expand All @@ -66,8 +66,8 @@ impl AttributeComparisonExpr {
#[inline]
#[must_use]
pub const fn new(
name: String,
value: String,
name: Box<str>,
value: Box<str>,
case_sensitivity: ParsedCaseSensitivity,
operator: AttrSelectorOperator,
) -> Self {
Expand Down Expand Up @@ -105,9 +105,9 @@ impl Debug for AttributeComparisonExpr {
/// An attribute check when attributes are received and parsed.
#[derive(PartialEq, Eq, Debug)]
pub(crate) enum OnAttributesExpr {
Id(String),
Class(String),
AttributeExists(String),
Id(Box<str>),
Class(Box<str>),
AttributeExists(Box<str>),
AttributeComparisonExpr(AttributeComparisonExpr),
}

Expand Down
11 changes: 4 additions & 7 deletions src/selectors_vm/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ use std::str::FromStr;
pub(crate) struct SelectorImplDescriptor;

#[derive(Clone, Default, Eq, PartialEq)]
pub struct CssString(pub String);
pub struct CssString(pub Box<str>);

impl<'a> From<&'a str> for CssString {
fn from(value: &'a str) -> Self {
Self(value.to_string())
Self(value.into())
}
}

impl ToCss for CssString {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
write!(dest, "{}", self.0)
fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
dest.write_str(&self.0)
}
}

Expand Down

0 comments on commit 9b00da5

Please sign in to comment.