starship_module_config_derive-0.1.1/Cargo.toml.orig010064400007650000024000000011431357301627600207150ustar0000000000000000[package] name = "starship_module_config_derive" version = "0.1.1" edition = "2018" authors = ["Matan Kushner "] homepage = "https://starship.rs" documentation = "https://starship.rs/guide/" repository = "https://github.com/starship/starship" readme = "README.md" license = "ISC" keywords = ["prompt", "shell", "bash", "fish", "zsh"] categories = ["command-line-utilities"] description = """ The cross-shell prompt for astronauts. ☄🌌️ """ exclude = ["docs/**/*"] [lib] name = "starship_module_config_derive" proc-macro = true [dependencies] proc-macro2 = "~1" quote = "~1" syn = "~1" starship_module_config_derive-0.1.1/Cargo.toml0000644000000022430000000000000151560ustar00# 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 believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "starship_module_config_derive" version = "0.1.1" authors = ["Matan Kushner "] exclude = ["docs/**/*"] description = "The cross-shell prompt for astronauts. ☄🌌️\n" homepage = "https://starship.rs" documentation = "https://starship.rs/guide/" readme = "README.md" keywords = ["prompt", "shell", "bash", "fish", "zsh"] categories = ["command-line-utilities"] license = "ISC" repository = "https://github.com/starship/starship" [lib] name = "starship_module_config_derive" proc-macro = true [dependencies.proc-macro2] version = "~1" [dependencies.quote] version = "~1" [dependencies.syn] version = "~1" starship_module_config_derive-0.1.1/LICENSE010064400007650000024000000013611357222455600170360ustar0000000000000000ISC License Copyright (c) 2019, Starship Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. starship_module_config_derive-0.1.1/README.md010064400007650000024000000000401356752543000173000ustar0000000000000000# starship_module_config_derive starship_module_config_derive-0.1.1/src/lib.rs010064400007650000024000000047201356020202100177120ustar0000000000000000extern crate proc_macro; extern crate proc_macro2; use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; #[proc_macro_derive(ModuleConfig)] pub fn derive_module_config(input: TokenStream) -> TokenStream { let dinput = parse_macro_input!(input as DeriveInput); impl_module_config(dinput) } fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream { let struct_ident = &dinput.ident; let (_impl_generics, ty_generics, where_clause) = dinput.generics.split_for_impl(); let mut from_config = quote! {}; let mut load_config = quote! {}; if let syn::Data::Struct(data) = dinput.data { if let syn::Fields::Named(fields_named) = data.fields { let mut load_tokens = quote! {}; let mut from_tokens = quote! {}; for field in fields_named.named.iter() { let ident = field.ident.as_ref().unwrap(); let ty = &field.ty; let new_load_tokens = quote! { if let Some(config_str) = config.get(stringify!(#ident)) { new_module_config.#ident = new_module_config.#ident.load_config(config_str); } }; let new_from_tokens = quote! { #ident: <#ty>::from_config(config.get(stringify!(#ident))?)?, }; load_tokens = quote! { #load_tokens #new_load_tokens }; from_tokens = quote! { #from_tokens #new_from_tokens } } load_config = quote! { fn load_config(&self, config: &'a toml::Value) -> Self { let mut new_module_config = self.clone(); if let toml::Value::Table(config) = config { #load_tokens } new_module_config } }; from_config = quote! { fn from_config(config: &'a toml::Value) -> Option { let config = config.as_table()?; Some(#struct_ident { #from_tokens }) } }; } } TokenStream::from(quote! { impl<'a> ModuleConfig<'a> for #struct_ident #ty_generics #where_clause { #from_config #load_config } }) } starship_module_config_derive-0.1.1/.cargo_vcs_info.json0000644000000001120000000000000171510ustar00{ "git": { "sha1": "f458a5e8c91bd6fd5b7df905f0b65e0e35034072" } }