Lines Matching +full:github +full:- +full:token
1 //! [![github]](https://github.com/dtolnay/proc-macro2) [![crates-io]](https://crates.io/crate…
3 //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo…
4 //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=55555…
5 //! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&lo…
12 //! [`proc_macro`]: https://doc.rust-lang.org/proc_macro/
14 //! - **Bring proc-macro-like functionality to other contexts like build.rs and
17 //! Meanwhile `proc_macro2` types may exist anywhere including non-macro code.
21 //! reimplementing non-macro equivalents of those libraries.
23 //! - **Make procedural macros unit testable.** As a consequence of being
29 //! [syn]: https://github.com/dtolnay/syn
30 //! [quote]: https://github.com/dtolnay/quote
43 //! pub fn my_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
62 //! The default feature set of proc-macro2 tracks the most recent stable
64 //! exposed by proc-macro2 by default.
68 //! rustc. We will polyfill those nightly-only APIs back to Rust 1.56.0. As
70 //! proc-macro2 may make breaking changes to them at any time.
73 //! RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build
80 //! Semver exempt methods are marked as such in the proc-macro2 documentation.
82 //! # Thread-Safety
85 //! types make use of thread-local memory, meaning they cannot be accessed from
88 // Proc-macro2 types in rustdoc of other crates get linked to here.
89 #![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.76")]
121 is turned on for the compilation of the proc-macro2 \
127 feature = "proc-macro",
136 #[cfg(feature = "proc-macro")]
174 #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))]
177 /// An abstract stream of tokens, or more concretely a sequence of token trees.
179 /// This type provides interfaces for iterating over token trees and for
180 /// collecting token trees into one stream.
182 /// Token stream is both the input and output of `#[proc_macro]`,
197 fn _new(inner: imp::TokenStream) -> Self { in _new()
204 fn _new_fallback(inner: fallback::TokenStream) -> Self { in _new_fallback()
211 /// Returns an empty `TokenStream` containing no token trees.
212 pub fn new() -> Self { in new()
217 pub fn is_empty(&self) -> bool { in is_empty()
225 fn default() -> Self { in default()
230 /// Attempts to break the string into tokens and parse those tokens into a token
241 fn from_str(src: &str) -> Result<TokenStream, LexError> { in from_str()
250 #[cfg(feature = "proc-macro")]
251 #[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))]
253 fn from(inner: proc_macro::TokenStream) -> Self { in from()
258 #[cfg(feature = "proc-macro")]
259 #[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))]
261 fn from(inner: TokenStream) -> Self { in from()
267 fn from(token: TokenTree) -> Self { in from()
268 TokenStream::_new(imp::TokenStream::from(token)) in from()
285 /// Collects a number of token trees into a single stream.
287 fn from_iter<I: IntoIterator<Item = TokenTree>>(streams: I) -> Self { in from_iter()
292 fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self { in from_iter()
297 /// Prints the token stream as a string that is supposed to be losslessly
298 /// convertible back into the same token stream (modulo spans), except for
302 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
307 /// Prints token in a form convenient for debugging.
309 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
315 pub fn span(&self) -> Span { in span()
321 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
327 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
347 fn _new(inner: imp::SourceFile) -> Self { in _new()
363 /// `--remap-path-prefix` was passed on the command line, the path as given
367 pub fn path(&self) -> PathBuf { in path()
373 pub fn is_real(&self) -> bool { in is_real()
380 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
393 fn _new(inner: imp::Span) -> Self { in _new()
400 fn _new_fallback(inner: fallback::Span) -> Self { in _new_fallback()
410 /// written directly at the macro call location (call-site hygiene) and
412 pub fn call_site() -> Self { in call_site()
419 pub fn mixed_site() -> Self { in mixed_site()
428 pub fn def_site() -> Self { in def_site()
434 pub fn resolved_at(&self, other: Span) -> Span { in resolved_at()
440 pub fn located_at(&self, other: Span) -> Span { in located_at()
455 pub fn unwrap(self) -> proc_macro::Span { in unwrap()
462 pub fn unstable(self) -> proc_macro::Span { in unstable()
471 pub fn source_file(&self) -> SourceFile { in source_file()
477 /// This method requires the `"span-locations"` feature to be enabled.
485 #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))]
486 pub fn start(&self) -> LineColumn { in start()
492 /// This method requires the `"span-locations"` feature to be enabled.
500 #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))]
501 pub fn end(&self) -> LineColumn { in end()
510 /// nightly-only. When called from within a procedural macro not using a
513 … /// [`proc_macro::Span::join`]: https://doc.rust-lang.org/proc_macro/struct.Span.html#method.join
514 pub fn join(&self, other: Span) -> Option<Span> { in join()
523 pub fn eq(&self, other: &Span) -> bool { in eq()
534 pub fn source_text(&self) -> Option<String> { in source_text()
541 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
546 /// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`).
549 /// A token stream surrounded by bracket delimiters.
561 /// the contained token or a delimited stream.
562 pub fn span(&self) -> Span { in span()
571 /// Configures the span for *only this token*.
573 /// Note that if this token is a `Group` then this method will not configure
587 fn from(g: Group) -> Self { in from()
593 fn from(g: Ident) -> Self { in from()
599 fn from(g: Punct) -> Self { in from()
605 fn from(g: Literal) -> Self { in from()
610 /// Prints the token tree as a string that is supposed to be losslessly
611 /// convertible back into the same token tree (modulo spans), except for
615 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
625 /// Prints token tree in a form convenient for debugging.
627 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
644 /// A delimited token stream.
653 /// Describes how a sequence of token trees is delimited.
667 /// Implicit delimiters may not survive roundtrip of a token stream through
673 fn _new(inner: imp::Group) -> Self { in _new()
677 fn _new_fallback(inner: fallback::Group) -> Self { in _new_fallback()
683 /// Creates a new `Group` with the given delimiter and token stream.
688 pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self { in new()
696 pub fn delimiter(&self) -> Delimiter { in delimiter()
702 /// Note that the returned token stream does not include the delimiter
704 pub fn stream(&self) -> TokenStream { in stream()
708 /// Returns the span for the delimiters of this token stream, spanning the
712 /// pub fn span(&self) -> Span {
715 pub fn span(&self) -> Span { in span()
722 /// pub fn span_open(&self) -> Span {
725 pub fn span_open(&self) -> Span { in span_open()
732 /// pub fn span_close(&self) -> Span {
735 pub fn span_close(&self) -> Span { in span_close()
742 pub fn delim_span(&self) -> DelimSpan { in delim_span()
761 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { in fmt()
767 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { in fmt()
772 /// A `Punct` is a single punctuation character like `+`, `-` or `#`.
784 /// another token or whitespace.
804 pub fn new(ch: char, spacing: Spacing) -> Self { in new()
813 pub fn as_char(&self) -> char { in as_char()
818 /// it's immediately followed by another `Punct` in the token stream, so
820 /// (`Joint`), or it's followed by some other token or whitespace (`Alone`)
822 pub fn spacing(&self) -> Spacing { in spacing()
827 pub fn span(&self) -> Span { in span()
840 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
846 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { in fmt()
861 /// - The empty string is not an identifier. Use `Option<Ident>`.
862 /// - A lifetime is not an identifier. Use `syn::Lifetime` instead.
887 /// An ident can be interpolated into a token stream using the `quote!` macro.
926 fn _new(inner: imp::Ident) -> Self { in _new()
942 /// As of this time `Span::call_site()` explicitly opts-in to "call-site"
947 /// Later spans like `Span::def_site()` will allow to opt-in to
948 /// "definition-site" hygiene meaning that identifiers created with this
961 /// style="padding-right:0;">syn::parse_str</code></a><code
962 /// style="padding-left:0;">::<Ident></code>
965 pub fn new(string: &str, span: Span) -> Self { in new()
975 pub fn new_raw(string: &str, span: Span) -> Self { in new_raw()
980 pub fn span(&self) -> Span { in span()
992 fn eq(&self, other: &Ident) -> bool { in eq()
1001 fn eq(&self, other: &T) -> bool { in eq()
1009 fn partial_cmp(&self, other: &Ident) -> Option<Ordering> { in partial_cmp()
1015 fn cmp(&self, other: &Ident) -> Ordering { in cmp()
1029 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1035 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1057 /// value specified is the first part of the token and the integral is
1060 /// broken into two tokens (`-` and positive literal).
1065 pub fn $name(n: $kind) -> Literal {
1076 /// value specified is the first part of the token. No suffix is
1077 /// specified on this token, meaning that invocations like
1081 /// be broken into two tokens (`-` and positive literal).
1086 pub fn $name(n: $kind) -> Literal {
1093 fn _new(inner: imp::Literal) -> Self { in _new()
1100 fn _new_fallback(inner: fallback::Literal) -> Self { in _new_fallback()
1137 /// Creates a new unsuffixed floating-point literal.
1140 /// the float's value is emitted directly into the token but no suffix is
1142 /// Literals created from negative numbers may not survive round-trips
1143 /// through `TokenStream` or strings and may be broken into two tokens (`-`
1150 pub fn f64_unsuffixed(f: f64) -> Literal { in f64_unsuffixed()
1155 /// Creates a new suffixed floating-point literal.
1158 /// specified is the preceding part of the token and `f64` is the suffix of
1159 /// the token. This token will always be inferred to be an `f64` in the
1161 /// round-trips through `TokenStream` or strings and may be broken into two
1162 /// tokens (`-` and positive literal).
1168 pub fn f64_suffixed(f: f64) -> Literal { in f64_suffixed()
1173 /// Creates a new unsuffixed floating-point literal.
1176 /// the float's value is emitted directly into the token but no suffix is
1178 /// Literals created from negative numbers may not survive round-trips
1179 /// through `TokenStream` or strings and may be broken into two tokens (`-`
1186 pub fn f32_unsuffixed(f: f32) -> Literal { in f32_unsuffixed()
1191 /// Creates a new suffixed floating-point literal.
1194 /// specified is the preceding part of the token and `f32` is the suffix of
1195 /// the token. This token will always be inferred to be an `f32` in the
1197 /// round-trips through `TokenStream` or strings and may be broken into two
1198 /// tokens (`-` and positive literal).
1204 pub fn f32_suffixed(f: f32) -> Literal { in f32_suffixed()
1210 pub fn string(string: &str) -> Literal { in string()
1215 pub fn character(ch: char) -> Literal { in character()
1220 pub fn byte_string(s: &[u8]) -> Literal { in byte_string()
1225 pub fn span(&self) -> Span { in span()
1235 /// the source bytes in range `range`. Returns `None` if the would-be
1239 /// nightly-only. When called from within a procedural macro not using a
1242 …/// [`proc_macro::Literal::subspan`]: https://doc.rust-lang.org/proc_macro/struct.Literal.html#met…
1243 pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> { in subspan()
1247 // Intended for the `quote!` macro to use when constructing a proc-macro2
1248 // token out of a macro_rules $:literal token, which is already known to be
1252 pub unsafe fn from_str_unchecked(repr: &str) -> Self { in from_str_unchecked()
1260 fn from_str(repr: &str) -> Result<Self, LexError> { in from_str()
1269 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1275 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1291 /// delimited groups, and returns whole groups as token trees.
1301 fn next(&mut self) -> Option<TokenTree> { in next()
1305 fn size_hint(&self) -> (usize, Option<usize>) { in size_hint()
1311 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1321 fn into_iter(self) -> IntoIter { in into_iter()