Skip to content

Call to get dyn Any of contexts/attachment values for Dynamic reports and attachments. #151

@Kile-Asmussen

Description

@Kile-Asmussen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions