summaryrefslogtreecommitdiff
path: root/bzipper_macros/src/generic_name/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bzipper_macros/src/generic_name/mod.rs')
-rw-r--r--bzipper_macros/src/generic_name/mod.rs39
1 files changed, 30 insertions, 9 deletions
diff --git a/bzipper_macros/src/generic_name/mod.rs b/bzipper_macros/src/generic_name/mod.rs
index a0c51f5..6fc0bc9 100644
--- a/bzipper_macros/src/generic_name/mod.rs
+++ b/bzipper_macros/src/generic_name/mod.rs
@@ -1,26 +1,28 @@
// Copyright 2024 Gabriel Bjørnager Jensen.
//
-// This file is part of bzipper.
+// This file is part of bZipper.
//
-// bzipper is free software: you can redistribute
+// bZipper is free software: you can redistribute
// it and/or modify it under the terms of the GNU
// Lesser General Public License as published by
// the Free Software Foundation, either version 3
// of the License, or (at your option) any later
// version.
//
-// bzipper is distributed in the hope that it will
+// bZipper is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Less-
-// er General Public License along with bzipper. If
+// er General Public License along with bZipper. If
// not, see <https://www.gnu.org/licenses/>.
use proc_macro2::TokenStream;
use quote::ToTokens;
+use std::fmt;
+use std::fmt::{Debug, Formatter};
use syn::{
GenericParam,
Generics,
@@ -33,9 +35,14 @@ use syn::{
/// A name of a genric.
#[derive(Clone)]
pub enum GenericName {
- Const( Ident),
+ /// Denotes a generic constant.
+ Const(Ident),
+
+ /// Denotes a generic lifetime.
Lifetime(Lifetime),
- Type( Ident),
+
+ /// Denotes a generic type.
+ Ty(Ident),
}
impl GenericName {
@@ -48,14 +55,28 @@ impl GenericName {
let name = match *generic {
GenericParam::Const( ref param) => Self::Const( param.ident.clone()),
GenericParam::Lifetime(ref param) => Self::Lifetime(param.lifetime.clone()),
- GenericParam::Type( ref param) => Self::Type( param.ident.clone()),
+ GenericParam::Type( ref param) => Self::Ty( param.ident.clone()),
};
names.push(name);
}
names
- }
+ }
+}
+
+impl Debug for GenericName {
+ #[inline]
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ let ident = match *self {
+ | Self::Const(ref ident)
+ | Self::Lifetime(Lifetime { ref ident, .. })
+ | Self::Ty(ref ident)
+ => ident,
+ };
+
+ Debug::fmt(ident, f)
+ }
}
impl ToTokens for GenericName {
@@ -65,7 +86,7 @@ impl ToTokens for GenericName {
match *self {
| Const(ref ident)
- | Type( ref ident)
+ | Ty( ref ident)
=> ident.to_tokens(tokens),
Lifetime(ref lifetime) => lifetime.to_tokens(tokens),