Pkg: actually require argument to be a repo

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2024-12-03 21:14:12 +01:00
parent 46b7e9282d
commit bf8f6721a4
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
5 changed files with 25 additions and 14 deletions

View File

@ -73,7 +73,7 @@ pub(crate) fn package(
.into();
};
let generic_struct: ::syn::ItemStruct = ::syn::parse_quote! {
pub struct test<R> where R: ::std::fmt::Debug + 'static {}
pub struct test<R> where R: ::bok::Repository + 'static {}
};
let (_, generics, where_clause) = generic_struct.generics.split_for_impl();
@ -506,7 +506,7 @@ pub(crate) fn package_impl_base_add(
let generic_struct: ::syn::ItemImpl = ::syn::parse_quote! {
impl<R> test for #pkg_type <R>
where
R: ::std::fmt::Debug + 'static
R: ::bok::Repository + 'static
{}
};
@ -775,7 +775,7 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
let expanded = quote! {
impl<R> ::core::fmt::Display for #name<R>
where
R: ::std::fmt::Debug
R: ::bok::Repository,
{
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>)
->::core::fmt::Result
@ -785,7 +785,7 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
}
impl<R> ::bok::PkgCode for #name<R>
where
R: ::std::fmt::Debug +'static
R: ::bok::Repository +'static,
{
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>)
->::core::fmt::Result
@ -848,7 +848,7 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
}
impl<R> #name<R>
where
R: ::std::fmt::Debug +'static + ::core::default::Default
R: ::bok::Repository + 'static + ::core::default::Default,
{
pub fn as_pkg(&self) -> &dyn ::bok::Pkg {
self
@ -869,7 +869,7 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
#[derive(::std::default::Default, ::std::fmt::Debug)]
pub struct #name_builder<R>
where
R: ::std::fmt::Debug +'static
R: ::bok::Repository + 'static,
{
_bok_repo: ::std::marker::PhantomData<R>,
#(#non_opt_fields: ::std::option::Option<#non_opt_types>,)*
@ -877,7 +877,7 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
}
impl<R> ::bok::PkgBuilder for #name_builder2<R>
where
R: ::std::fmt::Debug + 'static
R: ::bok::Repository + 'static,
{
fn name(&self) -> ::bok::PkgName {
use ::bok::Pkg;
@ -916,7 +916,7 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
}
impl<R> #name_builder3<R>
where
R: ::std::fmt::Debug +'static
R: ::bok::Repository +'static,
{
pub fn as_any(&self) -> &dyn ::std::any::Any {
self

View File

@ -538,6 +538,18 @@ pub(crate) fn repo_impl_methods(
fn_to_add.push(pkg_fn);
}
// keep sorted for easier debugging when expanding macros
fn_to_add
.sort_by(|a, b| a.sig.ident.to_string().cmp(&b.sig.ident.to_string()));
all_pkgs_types.sort_by(|a, b| {
a.segments
.last()
.unwrap()
.ident
.to_string()
.cmp(&b.segments.last().unwrap().ident.to_string())
});
let new_fn = fn_to_add.iter();
let mut all_impl_deps = Vec::with_capacity(all_pkgs_types.len());
@ -556,7 +568,6 @@ pub(crate) fn repo_impl_methods(
impl #bok_dep_trait for #local_ident {}
};
all_impl_deps.push(dep_view);
break;
}
quote! {
@ -586,7 +597,7 @@ pub(crate) fn repo_impl_pkg_deps(
.expect("#[::bok_macro::repo_impl_pkg_deps()]: no trait found")
.1;
let local_attrs = local.attrs.iter();
let (_, generics, where_clause) = local.generics.split_for_impl();
let (_, generics, _) = local.generics.split_for_impl();
let ident = &local.self_ty;
//let deps = Vec::<::syn::TraitItemFn>::new();
@ -611,7 +622,7 @@ pub(crate) fn repo_impl_pkg_deps(
quote! {
#(#local_attrs)
*
impl #impl_trait for #ident #generics #where_clause {
impl #impl_trait for #ident #generics {
#(#deps)
*
}

View File

@ -27,7 +27,7 @@ pub struct One {
impl<R> ::std::default::Default for One<R>
where
R: ::std::fmt::Debug,
R: ::bok::Repository,
{
fn default() -> Self {
One {

View File

@ -26,7 +26,7 @@ pub struct Three {
impl<R> ::std::default::Default for Three<R>
where
R: ::std::fmt::Debug,
R: ::bok::Repository,
{
fn default() -> Self {
Three {

View File

@ -26,7 +26,7 @@ pub struct Two {
impl<R> ::std::default::Default for Two<R>
where
R: ::std::fmt::Debug,
R: ::bok::Repository,
{
fn default() -> Self {
Two {