Add a version of into_token_stream that takes &self

This commit is contained in:
David Tolnay 2019-08-10 13:28:26 -07:00
parent 682eea40f3
commit c480dc7dfb
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -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()
}
}