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

considering trait inheritance #99

Closed
GopherJ opened this issue Apr 9, 2020 · 2 comments
Closed

considering trait inheritance #99

GopherJ opened this issue Apr 9, 2020 · 2 comments

Comments

@GopherJ
Copy link
Member

GopherJ commented Apr 9, 2020

Deref inheritance is an anti-pattern in rust because it's just passing actions/tasks to specific field. That means in our function we'll never be able to get child's reference.

So I propose to have better design and remove the usage of Deref in CachedEnforcer.

What can we do?
I think we can use trait inheritance, that means we should have a base/parent trait which can be called as CoreApi.

Then imple<T> InternalApi for T: CoreApi, impl<T> MgmtApi for T: InternalApi, Impl<T> RbacApi for T: MgmtApi

So finally for different types of enforcers they just need to implement CoreApi to get all the management functions.

How can we have different behaviours for different Enforcers?

No idea for now.

CachedEnforcer will have extra functions comparing to normal enforcers
SyncedEnforcer is a wrapper over Arc<RwLock<Enforcer>> or Arc<RwLock<CachedEnforcer>>

@GopherJ
Copy link
Member Author

GopherJ commented Apr 9, 2020

Also maybe specialization rust-lang/rust#31844 can help which requires:

#![feature(specialization)]

@GopherJ
Copy link
Member Author

GopherJ commented Apr 10, 2020

see #103 it's not fully implemented.

Like we cannot have auto impls InternalApi for T: CoreApi because we still need to keep some differences.

But it's enough for now and it will help the implementation on SyncedEnforcer

@GopherJ GopherJ closed this as completed Apr 10, 2020
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