Closed Lokathor closed 5 years ago
There's not necessarily a good way around this
The way around this is pub use fermium
in beryllium.
I said good way
What's wrong with that? I'm always annoyed when high level libraries that wrap C FFIs don't expose a way to get to the internals for when you know what you need to do.
A pub use fermium;
somewhat implies to end users that anything in fermium
is somehow something that a normal beryllium
user might be expected to use. It's clearly not.
Of course, an end user can at any time begin throwing down some transmute
action to jump past all the newtypes. However, the safety rules are often subtle and even I get it wrong. I don't like gatekeeping, but anyone who doesn't know enough about unsafe
to immediately see how to kick over my API (it's easy) probably shouldn't be encouraged in that direction.
anyone who doesn't know enough about unsafe to immediately see how to kick over my API (it's easy) probably shouldn't be encouraged in that direction
I can't imagine actually doing this to a lib I'm using unless I know I'll never have to update that lib, or if they make a hard guarantee that the wrappers are identical.
Almost every single wrapper type in beryllium
is repr(transparent)
on a *mut Thing
(v1 code) or NonNull<Thing>
(revised code) and then tagged with a PhantomData<&'lifetime ParentType>
for lifetime.
As to doing things that aren't wise: You're a good Rustacean, trained well by working in a professional setting to not overuse unsafe
. On the other hand, many of the Rust Community Discord, which is the rest of my audience basically, will pull out unsafe
without any sense of the dangers at the slightest provocation.
I trust specifically you to do the wise thing and read carefully, I don't trust the rest of them.
You could also pub use fermium as ffi
and naming functions to get pointers something like raw_handle()
which might make it clear that it's discouraged and not necessary for all but advanced usage.
That's much more convincing. I like that path.
the glium example uses fermium internals, and so it would need a fermium dependency, but because two versions of fermium both link SDL2 you wouldn't be able to mix versions.
There's not necessarily a good way around this, and if it can't be avoided then it should at least be noted in the example file.