Skip to content

Commit

Permalink
Allow Option in tw_join! and tw_merge! macros (#19)
Browse files Browse the repository at this point in the history
* remove AsRef impl in favor of granular impls for AsTailwindClass
  • Loading branch information
nicoburniske authored Apr 12, 2024
1 parent 76471ef commit 52056c2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
70 changes: 68 additions & 2 deletions fuse/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,77 @@ pub trait AsTailwindClass {
fn as_class(&self) -> &str;
}

impl<T> AsTailwindClass for T
impl AsTailwindClass for String {
fn as_class(&self) -> &str {
self.as_str()
}
}

impl AsTailwindClass for &str {
fn as_class(&self) -> &str {
self
}
}

impl<T> AsTailwindClass for &T
where
T: AsTailwindClass,
{
fn as_class(&self) -> &str {
(*self).as_class()
}
}

impl<T> AsTailwindClass for &mut T
where
T: AsTailwindClass,
{
fn as_class(&self) -> &str {
(**self).as_class()
}
}

impl<T> AsTailwindClass for std::rc::Rc<T>
where
T: AsTailwindClass,
{
fn as_class(&self) -> &str {
self.as_ref().as_class()
}
}

impl<T> AsTailwindClass for std::sync::Arc<T>
where
T: AsRef<str>,
T: AsTailwindClass,
{
fn as_class(&self) -> &str {
self.as_ref().as_class()
}
}

impl AsTailwindClass for std::borrow::Cow<'_, str> {
fn as_class(&self) -> &str {
self.as_ref()
}
}

impl<T> AsTailwindClass for Box<T>
where
T: AsTailwindClass,
{
fn as_class(&self) -> &str {
(**self).as_class()
}
}

impl<T> AsTailwindClass for Option<T>
where
T: AsTailwindClass,
{
fn as_class(&self) -> &str {
match self {
Some(t) => t.as_class(),
None => "",
}
}
}
2 changes: 1 addition & 1 deletion fuse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mod variant {

impl TailwindFuse for TailwindMerge {
fn fuse_classes(&self, class: &[&str]) -> String {
crate::core::merge::tw_merge_slice(class)
crate::merge::tw_merge_slice(class)
}
}

Expand Down

0 comments on commit 52056c2

Please sign in to comment.