From 87b83371e893ba273f9b1fdde0e7ba2a59f5c1f9 Mon Sep 17 00:00:00 2001 From: Luca Fulchir Date: Wed, 11 Dec 2024 20:53:27 +0100 Subject: [PATCH] tiny cleanup Signed-off-by: Luca Fulchir --- bok-macro/src/lib.rs | 12 ------- bok-macro/src/pkgs.rs | 78 ++++--------------------------------------- bok/src/collection.rs | 12 +++---- 3 files changed, 12 insertions(+), 90 deletions(-) diff --git a/bok-macro/src/lib.rs b/bok-macro/src/lib.rs index 95e24c9..879ba9e 100644 --- a/bok-macro/src/lib.rs +++ b/bok-macro/src/lib.rs @@ -345,15 +345,3 @@ impl ::syn::parse::Parse for PathList { Ok(PathList(result)) } } - -pub(crate) fn path_to_magic_export(p: &::syn::Path) -> ::syn::Path { - let mut tmp = p.clone(); - let new_id = { - macro_magic::mm_core::export_tokens_macro_ident( - &tmp.segments.last().unwrap().ident, - ) - }; - tmp.segments.last_mut().unwrap().ident = new_id; - - tmp -} diff --git a/bok-macro/src/pkgs.rs b/bok-macro/src/pkgs.rs index 33755ce..aef6743 100644 --- a/bok-macro/src/pkgs.rs +++ b/bok-macro/src/pkgs.rs @@ -1073,70 +1073,9 @@ pub(crate) fn package_impl_base_add( } pub(crate) fn derive_package(input: TokenStream) -> TokenStream { - let mut input = parse_macro_input!(input as DeriveInput); + let input = parse_macro_input!(input as DeriveInput); let name = input.ident.clone(); - let name_builder = quote::format_ident!("{name}Builder"); - let elements = match &input.data { - ::syn::Data::Struct(s) => match &s.fields { - syn::Fields::Named(n) => n.named.clone(), - _ => panic!("only named supported"), - }, - _ => panic!("only struct allowed"), - }; - let all_fields = elements.iter().filter_map(|field| { - if let Some(id) = field.ident.clone() { - if id.to_string() != "version" - && id.to_string() != "_bok_base" - && id.to_string() != "_bok_repo" - { - if field - .attrs - .iter() - .find(|&a| a.path().is_ident("option")) - .is_none() - { - return None; - } - return Some(&field.ident); - } - } - None - }); - let all_fields2 = all_fields.clone(); - let all_fields3 = all_fields.clone(); - let all_fields_mut = elements.iter().filter_map(|field| { - if let Some(id) = field.ident.clone() { - if id.to_string() != "version" - && id.to_string() != "_bok_base" - && id.to_string() != "_bok_repo" - { - return Some(quote::format_ident!("{}_mut", id.to_string())); - } - } - None - }); - let all_types = elements.iter().filter_map(|field| { - if let Some(id) = field.ident.clone() { - if id.to_string() != "version" - && id.to_string() != "_bok_base" - && id.to_string() != "_bok_repo" - { - return Some(&field.ty); - } - } - None - }); - let all_types2 = all_types.clone(); - - { - let ::syn::Data::Struct(ref mut ds) = input.data else { - panic!("::bok::package expected a struct"); - }; - let ::syn::Fields::Named(ref mut _old_nf) = ds.fields else { - panic!("::bok::package expected a named field"); - }; - } let pkg_struct = quote! { #input }; @@ -1227,21 +1166,18 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream { where R: ::bok::Repository + 'static + #trait_deps + ::core::default::Default, { + pub fn as_any(&self) -> &dyn ::std::any::Any { + self + } + pub fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any { + self + } pub fn as_pkg(&self) -> &dyn ::bok::Pkg { self } pub fn as_pkg_mut(&mut self) -> &mut dyn ::bok::Pkg { self } - pub fn builder() -> #name_builder { - #name_builder::::default() - } - #(pub fn #all_fields2(&self) -> &#all_types { - &self.#all_fields2 - })* - #(pub fn #all_fields_mut(&mut self) -> &#all_types2 { - &mut self.#all_fields3 - })* } }; diff --git a/bok/src/collection.rs b/bok/src/collection.rs index 0bf4d6a..ec1fb8c 100644 --- a/bok/src/collection.rs +++ b/bok/src/collection.rs @@ -15,13 +15,9 @@ * limitations under the License. */ -use ::std::{ - collections::BTreeMap, - sync::{Arc, RwLock}, - vec::Vec, -}; +use ::std::sync::{Arc, RwLock}; -use crate::{Path, PkgBuilder, PkgName, RepoName, Repository}; +use crate::{PkgBuilder, Repository}; #[derive(Debug, ::thiserror::Error)] pub enum Error { @@ -32,7 +28,9 @@ pub enum Error { } type ArcLock = Arc>; -type PkgMap = +/* +pub type PkgMap = BTreeMap, (Arc, ArcLock)>; +*/ pub trait Collection {}