-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #[builder(crate = "...")] at struct level
This allows setting the crate root for re-export scenarios. All hardcoded usage of `::derive_builder` in generated code has now been replaced by a `crate_root` variable, which contains the path to use. For backwards compatibility, this defaults to `::derive_builder`. Fixes #274
- Loading branch information
Showing
11 changed files
with
201 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::iter::FromIterator; | ||
|
||
use proc_macro2::{Group, Span, TokenStream, TokenTree}; | ||
|
||
/// Deeply change the span of some tokens, ensuring that the output only references `span`. | ||
/// | ||
/// Macros such as `quote_spanned` preserve the spans of interpolated tokens, which is useful. | ||
/// However, in some very specific scenarios it is desirable to suppress the original span | ||
/// information in favor of a different one. | ||
/// | ||
/// For more information, see [dtolnay/syn#309](https://github.com/dtolnay/syn/issues/309). | ||
pub(crate) fn change_span(tokens: TokenStream, span: Span) -> TokenStream { | ||
let mut result = vec![]; | ||
for mut token in tokens { | ||
match token { | ||
TokenTree::Group(group) => { | ||
let mut new_group = | ||
Group::new(group.delimiter(), change_span(group.stream(), span)); | ||
new_group.set_span(span); | ||
result.push(TokenTree::Group(new_group)); | ||
} | ||
_ => { | ||
token.set_span(span); | ||
result.push(token); | ||
} | ||
} | ||
} | ||
FromIterator::from_iter(result.into_iter()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.