Propagate _code to Pkg trait

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2024-03-25 09:08:18 +01:00
parent 5ba2440e12
commit 1d9ea5a699
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
2 changed files with 83 additions and 24 deletions

View File

@ -361,12 +361,13 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
Some(&self.base) Some(&self.base)
} }
} }
// FIXME: proper formatting of all functions
impl ::core::fmt::Display for #name { impl ::core::fmt::Display for #name {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>)
->::core::fmt::Result ->::core::fmt::Result
{ {
use ::bok::Pkg; use ::bok::Pkg;
let pkg = self.package(); let pkg = self.package_code();
pkg.fmt(f) pkg.fmt(f)
} }
} }

View File

@ -84,28 +84,61 @@ impl Repository for RepositoryEmpty {}
/// Implement common package operations /// Implement common package operations
pub trait Pkg: ::std::default::Default + ::core::fmt::Display { pub trait Pkg: ::std::default::Default + ::core::fmt::Display {
fn base(&self) -> Option<&impl Pkg>; fn base(&self) -> Option<&impl Pkg>;
fn prepare(&self) -> ::proc_macro2::TokenStream { fn prepare(&self) -> ::core::result::Result<(), ()> {
self.base().unwrap().prepare() self.base().unwrap().prepare()
} }
fn configure(&self) -> ::proc_macro2::TokenStream { fn prepare_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
self.base().unwrap().prepare()
}
}
fn configure(&self) -> ::core::result::Result<(), ()> {
self.base().unwrap().configure() self.base().unwrap().configure()
} }
fn build(&self) -> ::proc_macro2::TokenStream { fn configure_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
self.base().unwrap().configure()
}
}
fn build(&self) -> ::core::result::Result<(), ()> {
self.base().unwrap().build() self.base().unwrap().build()
} }
fn check(&self) -> ::proc_macro2::TokenStream { fn build_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
self.base().unwrap().build()
}
}
fn check(&self) -> ::core::result::Result<(), ()> {
self.base().unwrap().check() self.base().unwrap().check()
} }
fn install(&self) -> ::proc_macro2::TokenStream { fn check_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
self.base().unwrap().check()
}
}
fn install(&self) -> ::core::result::Result<(), ()> {
self.base().unwrap().install() self.base().unwrap().install()
} }
fn package(&self) -> ::proc_macro2::TokenStream { fn install_code(&self) -> ::proc_macro2::TokenStream {
let mut all = self.prepare(); ::quote::quote! {
all.extend(self.configure()); self.base().unwrap().install()
all.extend(self.build()); }
all.extend(self.check()); }
all.extend(self.install()); fn package(&self) -> ::core::result::Result<(), ()> {
all self.prepare()?;
self.configure()?;
self.build()?;
self.check()?;
self.install()
}
fn package_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
self.prepare()?;
self.configure()?;
self.build()?;
self.check()?;
self.install()
}
} }
} }
@ -113,7 +146,7 @@ pub trait Pkg: ::std::default::Default + ::core::fmt::Display {
pub struct PkgEmpty {} pub struct PkgEmpty {}
impl ::core::fmt::Display for PkgEmpty { impl ::core::fmt::Display for PkgEmpty {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { fn fmt(&self, _f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
Ok(()) Ok(())
} }
} }
@ -122,20 +155,45 @@ impl Pkg for PkgEmpty {
fn base(&self) -> Option<&impl Pkg> { fn base(&self) -> Option<&impl Pkg> {
None::<Self>.as_ref() None::<Self>.as_ref()
} }
fn prepare(&self) -> ::proc_macro2::TokenStream { fn prepare(&self) -> ::core::result::Result<(), ()> {
::quote::quote! {} Ok(())
} }
fn configure(&self) -> ::proc_macro2::TokenStream { fn prepare_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {} ::quote::quote! {
Ok(())
} }
fn build(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {}
} }
fn check(&self) -> ::proc_macro2::TokenStream { fn configure(&self) -> ::core::result::Result<(), ()> {
::quote::quote! {} Ok(())
}
fn configure_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
Ok(())
}
}
fn build(&self) -> ::core::result::Result<(), ()> {
Ok(())
}
fn build_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
Ok(())
}
}
fn check(&self) -> ::core::result::Result<(), ()> {
Ok(())
}
fn check_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
Ok(())
}
}
fn install(&self) -> ::core::result::Result<(), ()> {
Ok(())
}
fn install_code(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {
Ok(())
} }
fn install(&self) -> ::proc_macro2::TokenStream {
::quote::quote! {}
} }
} }