diff --git a/bok-macro/src/pkgs.rs b/bok-macro/src/pkgs.rs index 13cbebd..d09911c 100644 --- a/bok-macro/src/pkgs.rs +++ b/bok-macro/src/pkgs.rs @@ -276,7 +276,7 @@ pub(crate) fn deps_build( * } #[::macro_magic::export_tokens(#pkg_trait)] - pub trait #pkg_trait { + pub trait #pkg_trait: ::bok::Repository { #(fn #deps(&self) -> ::std::boxed::Box;) * } diff --git a/bok-macro/src/repos.rs b/bok-macro/src/repos.rs index d20307a..25411a5 100644 --- a/bok-macro/src/repos.rs +++ b/bok-macro/src/repos.rs @@ -227,6 +227,9 @@ pub(crate) fn derive_repository(input: TokenStream) -> TokenStream { _ => None, } } + fn as_any(&self) -> &dyn ::std::any::Any { + self + } } }.into() } diff --git a/bok-utils/src/repos/pkgs/one.rs b/bok-utils/src/repos/pkgs/one.rs index defe0f0..e775677 100644 --- a/bok-utils/src/repos/pkgs/one.rs +++ b/bok-utils/src/repos/pkgs/one.rs @@ -48,7 +48,7 @@ impl ::bok::Pkg for One { } fn dependencies_set( &self, - _repo: ::std::sync::Arc, + repo: ::std::sync::Arc, _build: &::bok::deps::Build, _runtime: &::bok::deps::Runtime, ) -> Result<(), ()> { diff --git a/bok-utils/src/repos/pkgs/two.rs b/bok-utils/src/repos/pkgs/two.rs index 188c223..e59746a 100644 --- a/bok-utils/src/repos/pkgs/two.rs +++ b/bok-utils/src/repos/pkgs/two.rs @@ -45,10 +45,16 @@ impl ::std::default::Default for Two { impl ::bok::Pkg for Two { fn dependencies_set( &self, - _repo: ::std::sync::Arc, + repo: ::std::sync::Arc, _build: &::bok::deps::Build, _runtime: &::bok::deps::Runtime, ) -> Result<(), ()> { + let repo_any = repo.as_any(); + let Some(actual_repo) = repo_any.downcast_ref::() else { + return Err(()); + }; + let _ = actual_repo.one(); + Ok(()) } } diff --git a/bok/src/lib.rs b/bok/src/lib.rs index 6a686db..ba8575c 100644 --- a/bok/src/lib.rs +++ b/bok/src/lib.rs @@ -52,6 +52,7 @@ pub trait Repository: ::core::fmt::Debug { fn path(&self) -> Path; fn pkg_list(&self) -> &[&'static str]; fn get(&self, pkg_name: &str) -> Option<::std::boxed::Box>; + fn as_any(&self) -> &dyn ::std::any::Any; } /// This is an empty Package List. @@ -75,6 +76,9 @@ impl Repository for RepositoryEmpty { fn get(&self, _pkg_name: &str) -> Option<::std::boxed::Box> { None } + fn as_any(&self) -> &dyn ::std::any::Any { + self + } } /// Print the code of the package