Lokathor / beryllium

An opinionated set of high level wrappers for the `fermium` SDL2 bindings.
https://docs.rs/beryllium
63 stars 6 forks source link

Glium example depends on fermium weirdly #61

Closed Lokathor closed 5 years ago

Lokathor commented 5 years ago

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.

thomcc commented 5 years ago

There's not necessarily a good way around this

The way around this is pub use fermium in beryllium.

Lokathor commented 5 years ago

I said good way

thomcc commented 5 years ago

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.

Lokathor commented 5 years ago

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.

thomcc commented 5 years ago

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.

Lokathor commented 5 years ago

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.

thomcc commented 5 years ago

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.

Lokathor commented 5 years ago

That's much more convincing. I like that path.

Lokathor commented 5 years ago

Fixed in https://github.com/Lokathor/beryllium/pull/65