linkme icon indicating copy to clipboard operation
linkme copied to clipboard

Implement disjointed statics

Open CAD97 opened this issue 1 year ago • 3 comments

I'm not super enthused about the impl duplicating much of disjointed_slice, and certainly wants some more test coverage, but it works sufficiently enough for initial review of the approach.

The initial vision for #81 allowed using unsized types for the static (e.g. dyn Trait), but to avoid silently introducing extra indirection, this restricts disjointed statics to sized types. For dyn Trait injection, you can use &dyn Trait as the static type. However, no shorthand is provided for linking static IMPL: Concrete to such a declaration, and downstream must create the correctly typed static themselves. This is at least in part due to the moderate difficulty of hygienically naming the correct item type from downstream.

This feels a little bad for linking fn(), since ending up with &fn() is kind of silly. We might want for a separate "disjointed fn" which links the function item instead of a static item.

closes #81

CAD97 avatar Mar 11 '24 21:03 CAD97

... oops, didn't fix the nonwindows cfg. Had to go afk after submitting this but I'll fix that when I get back.

CAD97 avatar Mar 11 '24 21:03 CAD97

Potential alternative name: #[linkme::injected]. With that name I'd consider it important to work for fn items directly. I can't think of a good way to directly link some static and create a new static item for others, unfortunately.

CAD97 avatar Mar 12 '24 19:03 CAD97

I have not gotten a chance to review this yet — sorry about the delay. I am still occupied with a different project (which I had though might be done by now, but isn't). If I were to add you on linkme as a maintainer, could you merge this yourself, or get a review from anyone else and then merge? Of course, I am not sure whether this defeats your intention for putting the new macro into this crate as opposed to your own crate.

dtolnay avatar Aug 11 '24 07:08 dtolnay