| Crates.io | impl_variadics |
| lib.rs | impl_variadics |
| version | 0.3.0 |
| created_at | 2024-03-23 09:54:12.288093+00 |
| updated_at | 2024-05-06 08:15:25.437789+00 |
| description | a macro to generate repetitive idents etc. usually used to implement trait for tuples. |
| homepage | |
| repository | https://github.com/Fancyflame/impl_variadics |
| max_upload_size | |
| id | 1183453 |
| size | 15,209 |
A macro for generate variadic generics.
The syntax is similar to quote.
impl_variadics! {
..4 "T*" => {
impl<#(#T0),*> Display for TupleDisplay<(#(#T0,)*)>
where
#(#T0: Display,)*
{
fn fmt(&self, _f: &mut Formatter) -> Result {
#(self.0.#index.fmt(_f)?;)*
Ok(())
}
}
};
/*
10..20 "Ty*pe" "my_index_*" "and_more_*" => {
...
}
*/
}
it expands to
impl Display for TupleDisplay<()> {
fn fmt(&self, _f: &mut Formatter) -> Result {
Ok(())
}
}
impl<T0> Display for TupleDisplay<(T0,)>
where
T0: Display,
{
fn fmt(&self, _f: &mut Formatter) -> Result {
self.0 .0.fmt(_f)?;
Ok(())
}
}
impl<T0, T1> Display for TupleDisplay<(T0, T1)>
where
T0: Display,
T1: Display,
{
fn fmt(&self, _f: &mut Formatter) -> Result {
self.0 .0.fmt(_f)?;
self.0 .1.fmt(_f)?;
Ok(())
}
}
impl<T0, T1, T2> Display for TupleDisplay<(T0, T1, T2)>
where
T0: Display,
T1: Display,
T2: Display,
{
fn fmt(&self, _f: &mut Formatter) -> Result {
self.0 .0.fmt(_f)?;
self.0 .1.fmt(_f)?;
self.0 .2.fmt(_f)?;
Ok(())
}
}
2..10."T*": a custom identifier pattern. will replace all * with indexes.
you can try other patterns like "Type" or "index_*".#index: a builtin iterator gives 0 ~ max_index.#length: a builtin integer equals to iterator length.#T0: custom identifier. it gives T0, T1, T2 ... TN, where N is the T*, replace all *
with 0.