Skip to content

Preventing TraitObjects from handing out objects with 'static lifetime #16

Description

@kulst

Hi :)
I am currently working on a Rust API for the Apache Celix framework and I am considering to utilize this amazing crate for it.
As to make everything safe is quite a complex topic I would like to ask for some advice from you.

Apache Celix is a C written software that dynamically loads and unloads so called bundles which are basically dynamic libraries with a little metadata. Each bundle must define a set of predefined functions (create, start, stop, delete). So the framework can communicate to the bundle to allocate/deallocate necessary resources. This means the framework has full control over the loading/unloading of bundles.

Each bundle can register services at the framework that can then be used by other bundles. In the C world a service is just a struct with a handle and one or more function pointers that use the handle.
I want to safely provide services from the Rust world.

In my eyes this concept maps very well to TraitObjects like your crate provides in a ffi safe manner. Also the ability to generate C/C++ code for such TraitObjects comes in very handy as this makes it possible to use such Rust services from C/C++ written bundles.

As services can be used from many bundles at the same time a service user is only provided with a MyTraitRef. If a service should mutate internal state thread safe interior mutability is necessary.

However there is one problem I could not find a solution to yet:
A service/TraitObject could hand out a 'static reference to a bundle ressource. You also pointed out this problem in the readme.
To be safe I need to make sure that a trait which has the #[cglue_trait] attribute does not provide a return type with 'static lifetime.

Would you see a way to make this sure?
Do you see a different problem I may not have concidered?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions