chiark / gitweb /
coloured_string: Simplify a macro
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Feb 2024 14:09:14 +0000 (14:09 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Feb 2024 14:28:05 +0000 (14:28 +0000)
We can use a non-elided anonymous lifetime here, which makes the macro
a lot simpler.

src/coloured_string.rs

index 01221cae8ec673c76bfa30fd212a53c9c733d468..c35094ae349f67727a629a5c11a94a9afc9d98f4 100644 (file)
@@ -213,8 +213,8 @@ impl<'a> ColouredStringSlice<'a> {
 // So instead let's do some macro business, to avoid copy-pasting four
 // times.
 macro_rules! impl_Add {
-    ($type:ty, $($life:lifetime)?) => {
-        impl<$($life,)? U: ColouredStringCommon> std::ops::Add<U> for $type {
+    ($type:ty) => {
+        impl<U: ColouredStringCommon> std::ops::Add<U> for $type {
             type Output = ColouredString;
             fn add(self, rhs: U) -> ColouredString {
                 ColouredString::concat(self, rhs)
@@ -223,10 +223,10 @@ macro_rules! impl_Add {
     };
 }
 
-impl_Add!(ColouredString,);
-impl_Add!(&ColouredString,);
-impl_Add!(ColouredStringSlice<'a>, 'a);
-impl_Add!(&ColouredStringSlice<'a>, 'a);
+impl_Add!(ColouredString);
+impl_Add!(&ColouredString);
+impl_Add!(ColouredStringSlice<'_>);
+impl_Add!(&ColouredStringSlice<'_>);
 
 pub struct ColouredStringCharIterator<'a> {
     cs: ColouredStringSlice<'a>,