typewit_proc_macros-1.8.1/.cargo_vcs_info.json0000644000000001610000000000100151350ustar { "git": { "sha1": "02d33f5ea05773ed868fc297405aee39d766e758" }, "path_in_vcs": "typewit_proc_macros" }typewit_proc_macros-1.8.1/Cargo.toml0000644000000015310000000000100131350ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.57.0" name = "typewit_proc_macros" version = "1.8.1" authors = ["rodrimati1992 "] include = [ "Cargo.toml", "src/**/*.rs", "LICENSE-ZLIB.md", ] description = "implementation detail of typewit" license = "Zlib" repository = "https://github.com/rodrimati1992/typewit/" [lib] proc-macro = true [dependencies] typewit_proc_macros-1.8.1/Cargo.toml.orig000064400000000000000000000006131046102023000166160ustar 00000000000000[package] name = "typewit_proc_macros" version = "1.8.1" edition = "2021" authors = ["rodrimati1992 "] rust-version = "1.57.0" license = "Zlib" description = "implementation detail of typewit" repository = "https://github.com/rodrimati1992/typewit/" include = [ "Cargo.toml", "src/**/*.rs", "LICENSE-ZLIB.md", ] [lib] proc-macro = true [dependencies] typewit_proc_macros-1.8.1/LICENSE-ZLIB.md000064400000000000000000000015271046102023000160760ustar 00000000000000Copyright (c) 2023 Matias Rodriguez. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.typewit_proc_macros-1.8.1/src/lib.rs000064400000000000000000000032761046102023000156420ustar 00000000000000use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree}; use core::iter::once; fn unwrap_paren(tt: Option, where_: &str) -> proc_macro::Group { match tt { Some(TokenTree::Group(group)) if group.delimiter() == Delimiter::Parenthesis => { group } _ => panic!("expected {} to be `()`-delimited ", where_) } } // Generates an impl block where the span of `impl` and `for` is copied from another token. // // input: `($($prev_tokens:tt)*) $for_span:tt $($rem:tt)*` #[doc(hidden)] #[proc_macro] pub fn __impl_with_span(input: TokenStream) -> TokenStream { let mut iter = input.into_iter(); let impl_span = match iter.next().expect("expected second token tree to exist") { TokenTree::Group(group) if group.delimiter() == Delimiter::None => { group.stream().into_iter().next().unwrap().span() } tt => tt.span() }; let mut out = unwrap_paren(iter.next(), "second token tree (impl attributes)").stream(); out.extend(once(TokenTree::Ident(Ident::new("impl", impl_span)))); out.extend(unwrap_paren(iter.next(), "third token tree (impld trait)").stream()); out.extend(once(TokenTree::Ident(Ident::new("for", impl_span)))); out.extend(unwrap_paren(iter.next(), "fourth token tree (impld type)").stream()); out.extend(unwrap_paren(iter.next(), "fifth token tree (where clause)").stream()); { let mut group = Group::new( Delimiter::Brace, unwrap_paren(iter.next(), "sixth token tree (associated items)").stream(), ); group.set_span(group.span().located_at(impl_span)); out.extend(once(TokenTree::Group(group))); } out }