Pkg dyn base
Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
parent
103ba9b926
commit
a98b1fb653
@ -209,10 +209,15 @@ pub fn impl_package(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as ::syn::ItemImpl);
|
||||
|
||||
let base: ::syn::ImplItem = ::syn::parse_quote! {
|
||||
fn base(&self) -> ::core::option::Option<&impl ::bok::Pkg> {
|
||||
fn base(&self) -> ::core::option::Option<&dyn ::bok::Pkg> {
|
||||
Some(&self.base)
|
||||
}
|
||||
};
|
||||
let base_mut: ::syn::ImplItem = ::syn::parse_quote! {
|
||||
fn base_mut(&mut self) -> ::core::option::Option<&mut dyn ::bok::Pkg> {
|
||||
Some(&mut self.base)
|
||||
}
|
||||
};
|
||||
|
||||
for mut impl_item in ast.items.iter_mut() {
|
||||
if let ::syn::ImplItem::Fn(ref mut fn_impl) = &mut impl_item {
|
||||
@ -227,6 +232,7 @@ pub fn impl_package(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
ast.items.push(base);
|
||||
ast.items.push(base_mut);
|
||||
|
||||
quote! {
|
||||
#ast
|
||||
@ -491,6 +497,12 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
|
||||
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()
|
||||
}
|
||||
|
@ -89,12 +89,10 @@ impl Repository for RepositoryEmpty {}
|
||||
|
||||
/// Implement common package operations
|
||||
pub trait Pkg:
|
||||
::std::default::Default
|
||||
+ ::core::fmt::Debug
|
||||
+ ::core::fmt::Display
|
||||
+ ::std::any::Any
|
||||
::core::fmt::Debug + ::core::fmt::Display + ::std::any::Any
|
||||
{
|
||||
fn base(&self) -> ::core::option::Option<&impl Pkg>;
|
||||
fn base(&self) -> ::core::option::Option<&dyn Pkg>;
|
||||
fn base_mut(&mut self) -> ::core::option::Option<&mut dyn Pkg>;
|
||||
fn prepare(&self) -> ::core::result::Result<(), ()> {
|
||||
self.base().unwrap().prepare()
|
||||
}
|
||||
@ -162,8 +160,11 @@ impl ::core::fmt::Display for PkgEmpty {
|
||||
}
|
||||
|
||||
impl Pkg for PkgEmpty {
|
||||
fn base(&self) -> Option<&impl Pkg> {
|
||||
None::<Self>.as_ref()
|
||||
fn base(&self) -> Option<&dyn Pkg> {
|
||||
None
|
||||
}
|
||||
fn base_mut(&mut self) -> Option<&mut dyn Pkg> {
|
||||
None
|
||||
}
|
||||
fn prepare(&self) -> ::core::result::Result<(), ()> {
|
||||
::core::result::Result::Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user