diff --git a/src/to_tokens.rs b/src/to_tokens.rs index 90ccb8a..7f98083 100644 --- a/src/to_tokens.rs +++ b/src/to_tokens.rs @@ -54,6 +54,16 @@ pub trait ToTokens { /// ``` fn to_tokens(&self, tokens: &mut TokenStream); + /// Convert `self` directly into a `TokenStream` object. + /// + /// This method is implicitly implemented using `to_tokens`, and acts as a + /// convenience method for consumers of the `ToTokens` trait. + fn to_token_stream(&self) -> TokenStream { + let mut tokens = TokenStream::new(); + self.to_tokens(&mut tokens); + tokens + } + /// Convert `self` directly into a `TokenStream` object. /// /// This method is implicitly implemented using `to_tokens`, and acts as a @@ -62,9 +72,7 @@ pub trait ToTokens { where Self: Sized, { - let mut tokens = TokenStream::new(); - self.to_tokens(&mut tokens); - tokens + self.to_token_stream() } }