Rootcause's support for type erasure/dynamic typing is pretty great, but also something of a walled garden. It would be potentially useful to have something like:
impl<'a, O, T> ReportRef<Dynamic, O, T> {
fn current_context_dyn_any(&self) -> &dyn Any {
/* implementation details */
}
}
My proposal for an implementation is to include a field in the vtables of type:
as_any: fn(&C /* or A*/) -> &dyn Any
which will get a value at creation time given as
as_any: |c: &C /* or a: &A */| c as &dyn Any
and then this is used in the obvious manner to implement appropriate functions for RawReport(Ref/Mut) and RawAttachment(Ref/Mut), which are then used to implement according functions in Report(|Ref|Mut)<Dynamic> and ReportAttachment(|Ref|Mut)<Dynamic>.
Pros:
- Better integration with other libraries owing to using the 'lowest common denominator' for dynamic typing.
Cons:
- An extra field in the vtables.
- Functionality is technically already provided by
current_context_type_id and downcast_current_context and the like.
Scope:
- Six new functions in public API (owned, ref, mut X report, attachments).
- Six new functions in rootcause internals raw API.
- Two extra function-typed fields in vtable API.
- An extra field in each of the two vtable structs.
- Probably little to no unsafe code (apart from access to the
raw field.)
- Doc comment examples.
Rootcause's support for type erasure/dynamic typing is pretty great, but also something of a walled garden. It would be potentially useful to have something like:
My proposal for an implementation is to include a field in the vtables of type:
which will get a value at creation time given as
and then this is used in the obvious manner to implement appropriate functions for
RawReport(Ref/Mut)andRawAttachment(Ref/Mut), which are then used to implement according functions inReport(|Ref|Mut)<Dynamic>andReportAttachment(|Ref|Mut)<Dynamic>.Pros:
Cons:
current_context_type_idanddowncast_current_contextand the like.Scope:
rawfield.)