Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- pub struct Endpoint<R, M> {
- pub rep: R,
- _back: PhantomData<M>,
- }
- impl<R, M> Endpoint<R, M> {
- pub fn new(rep: R) -> Self {
- Endpoint {
- rep,
- _back: PhantomData,
- }
- }
- }
- trait IntoEndpoint<R> {
- fn into_endpoint<M: ?Sized>(self) -> Endpoint<R, *const M>;
- }
- trait Service<M> where M: Mounter + ?Sized {
- fn mount_service(self, mounter: &mut M);
- }
- impl<R, M> Service<M> for Endpoint<R, *const M> where R: std::fmt::Display, M: Mounter + ?Sized{
- fn mount_service(self, mounter: &mut M) {
- unimplemented!()
- }
- }
- trait Mounter where Self::Back: BackendTrait {
- type Back;
- fn mount_service<S: Service<Self>>(&mut self, service: S) where Self: Sized {
- service.mount_service(self);
- }
- fn mount_repository<Repo: Repository>(&mut self, _rep: &Repo) {
- Repo::mount::<Self>(self);
- }
- }
- trait Repository {
- fn mount<M: Mounter + ?Sized>(mounter: &mut M);
- }
- pub trait BackendTrait {}
- pub struct RocketRetriever;
- pub struct RocketMounter;
- impl BackendTrait for RocketRetriever {}
- impl Mounter for RocketMounter {
- type Back = RocketRetriever;
- }
- pub struct MyOwnEndpoint { pub val: u32 }
- impl IntoEndpoint<u32> for MyOwnEndpoint {
- fn into_endpoint<M: ?Sized>(self) -> Endpoint<u32, *const M> {
- Endpoint::new( self.val )
- }
- }
- pub struct TestRepo;
- impl Repository for TestRepo {
- fn mount<M: Mounter + ?Sized>(mounter: &mut M) {
- let my_own_endpoint = MyOwnEndpoint { val: 5 };
- let endpoint = my_own_endpoint.into_endpoint::<M>();
- endpoint.mount_service(mounter);
- }
- }
- fn main() {
- let mut rocket_mounter = RocketMounter { };
- let test_repo = TestRepo { };
- rocket_mounter.mount_repository(&test_repo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement