Abstract Impl
This crate enables users to generate generic (abstract) implementations for traits, with bounds on the Self type.
The idea for this came primarily from Context-Generic Programming, I wanted the core without all the bells and whistles (no providers, consumers and contexts). I noticed that it primarily empowers the programmer to provide generic implementations for traits, that types can choose to implement.
The name abstract_impl comes from the possibility of having that in rust (abstract is a reserved keyword), you could have abstract impl.
Use
use abstract_impl;
// Create an implementation
;
impl_DebugToString!;
Features:
- type errors at the right place
- check that all items of the trait are implemented
- use of self type with bounds
- automatic implementation macro
A more elaborate showcase
use abstract_impl;
use *;
use *;
impl_FormatUsingDebug!;
impl_PrintUsingFormat!;
No Macro
Sometimes the impl_Impl macros might not be desired.
In that case it may be disabled with the no_macro option.
use abstract_impl;
// impl_DebugToString(());
// No impl_Impl macro generated
// Manually use it instead
;
No Dummy
abstract_impl automatically generates a dummy implementation for the trait, to check that all items are implemented.
This may result in problems for traits that have super traits.
In that case it may be disabled with the no_dummy option.
use abstract_impl;
If no_dummy wasn't used, you would get an error that Dummy doesn't implement Ord.
Legacy Order
By default impl Impl for Trait is used.
Some people may prefer the previous order impl Trait for Impl.
use abstract_impl;
How it is made
(WIP)
Future Plans
- const item in impl (currently has no generics)
- generics for trait and impl
- self in macros (expand inner first)
Changelog
- 0.1.0 Working version with basic documentation
- 0.2.0 Reverse trait and name position (now impl Impl for Trait) and extended documentation
License
This code is MIT licensed.