Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trait_alias should impl for trait objects too. #34

Open
Leoyzen opened this issue May 30, 2022 · 0 comments
Open

trait_alias should impl for trait objects too. #34

Leoyzen opened this issue May 30, 2022 · 0 comments

Comments

@Leoyzen
Copy link

Leoyzen commented May 30, 2022

// crate: facade
// we define some facade interfaces here
pub trait GenericInterface: Any + Send + Sync;
// or using nightly trait alias
pub trait GenericInterface = Any + Send + Sync;

pub trait SomeInterface: GenericInterface;


// crate: service
pub struct Service {}
impl Component for Service {
    type Interface = Box<dyn GenericInterface>;
    ...
}


// crate: application
// we use shaku here to organize module and code
use shaku::Interface;
// but we can't using GenericInterface here because shaku::Interface only impl for those size type (T) not object trait.
impl shaku::Interface for dyn GenericInterface {}

the Interface and other defs should be impl for trait object itself too.

// implement for all T
impl<T: Any + Send + Sync> Interface for T {}

// implement for all trait object
impl Interface for dyn Any + Send + Sync {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant