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 mut ast = parse_macro_input!(input as ::syn::ItemImpl);
|
||||||
|
|
||||||
let base: ::syn::ImplItem = ::syn::parse_quote! {
|
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)
|
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() {
|
for mut impl_item in ast.items.iter_mut() {
|
||||||
if let ::syn::ImplItem::Fn(ref mut fn_impl) = &mut impl_item {
|
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);
|
||||||
|
ast.items.push(base_mut);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#ast
|
#ast
|
||||||
@ -491,6 +497,12 @@ pub fn derive_package(input: TokenStream) -> TokenStream {
|
|||||||
pub fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any {
|
pub fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any {
|
||||||
self
|
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 {
|
pub fn builder() -> #name_builder {
|
||||||
#name_builder::default()
|
#name_builder::default()
|
||||||
}
|
}
|
||||||
|
@ -89,12 +89,10 @@ impl Repository for RepositoryEmpty {}
|
|||||||
|
|
||||||
/// Implement common package operations
|
/// Implement common package operations
|
||||||
pub trait Pkg:
|
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<(), ()> {
|
fn prepare(&self) -> ::core::result::Result<(), ()> {
|
||||||
self.base().unwrap().prepare()
|
self.base().unwrap().prepare()
|
||||||
}
|
}
|
||||||
@ -162,8 +160,11 @@ impl ::core::fmt::Display for PkgEmpty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pkg for PkgEmpty {
|
impl Pkg for PkgEmpty {
|
||||||
fn base(&self) -> Option<&impl Pkg> {
|
fn base(&self) -> Option<&dyn Pkg> {
|
||||||
None::<Self>.as_ref()
|
None
|
||||||
|
}
|
||||||
|
fn base_mut(&mut self) -> Option<&mut dyn Pkg> {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
fn prepare(&self) -> ::core::result::Result<(), ()> {
|
fn prepare(&self) -> ::core::result::Result<(), ()> {
|
||||||
::core::result::Result::Ok(())
|
::core::result::Result::Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user