Closed sffc closed 1 month ago
My hope was that namespacing could be done with an attribute, so you do something like #[diplomat::namespace(foo)]
and it gets namespaced under foo
, but you can still organize your code however you'd like.
It's also worth discussing if the namespacing should be done for everyone or if we should have a #[diplomat::cpp::namespace(foo)]
attribute instead
it just puts Bar in the global (capi) namespace.
This isn't correct, the capi namespace is for the C headers. It puts it in the global namespace.
I think what we should do here is have diplomat::cpp::namespace(icu4x)
and diplomat::c::namespace(ICU4X)
(and nothing for JS), where the C++ implementation uses a C++ namespace (and can be applied to the bridge module or the individual type), and the C implementation just tacks on a prefix.
If we do this we should do this in the holistic backend attribute system designed in #235
n.b. currently we do not do any attribute merging in the AST except for CFGs (https://github.com/rust-diplomat/diplomat/blob/133a10534cad9f29e7b9ddfc1aea687c5e3b8274/core/src/ast/attrs.rs#L24)
For namespacing it would be nice to use a similar mechanism to "inherit" namespace and rename attributes from the module def.
I think there are two things here:
I think we should deal with these separately. For Dart I don't need any fancy modularisation (because Dart doesn't support that), but I do want generate a Dart API without ICU4X..
prefixes. So in icu_capi
I'd like to change
#[diplomat::bridge]
mod ffi {
struct ICU4XLocale(...)
}
to
#[diplomat::bridge(prefix = "ICU4X")]
mod ffi {
struct Locale(...)
}
to allow using nicer names in Dart.
I'd call it c_prefix
but yeah
Splitting out C++ into https://github.com/rust-diplomat/diplomat/issues/427
Closing in favor of https://github.com/rust-diplomat/diplomat/issues/688
The above code should generate a namespaced
Bar
object. Right now the whole modulefoo
just gets ignored, and if I annotate it with another#[diplomat::bridge]
, it just putsBar
in the global (capi
) namespace.