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)
}
}
// FIXME: proper formatting of all functions
impl ::core::fmt::Display for #name {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>)
->::core::fmt::Result
{
use ::bok::Pkg;
let pkg = self.package();
let pkg = self.package_code();
pkg.fmt(f)
}
}

View File

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