Open Bug 1869047 Opened 1 year ago Updated 1 year ago

Produce additional, more idiomatic Rust bindings

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

People

(Reporter: leftmostcat, Unassigned)

Details

Attachments

(1 file)

PCOM's existing Rust bindings for a high degree of flexibility and low overhead by allowing developers to work directly with pointers or allow XPCOM to produce a slightly friendlier function signature for implementations, but do not allow developers to opt into automatic generation of the friendlier stubs for an entire interface or to get the friendlier interface for an existing implementation acquired via get_service() or create_instance().

The attached patch provides a proof-of-concept for a pattern allowing Rust code to both implement and consume interfaces as traits. The pattern builds on top of the existing bindings and could presumably co-exist with them in order to provide greater flexibility. While the interface-specific glue code in the patch is hand-written, I believe it to be generatable.

I'm soliciting feedback on this pattern, both in terms of feasibility and suitability. Further discussion and documentation is included as comments in the patch. The hope is that it allows developers to take for granted the soundness guarantees that the xpcom crate can give (pointers are non-null and will remain valid due to refcounting) while also working easily with Rust patterns. This does come at some cost (Ensure::ensure() is called for each pointer and refcounting is primarily delegated to Rc), but making this an opt-in approach allows developers to make that decision once for an entire interface rather than piecemeal for each function with the associated boilerplate.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: