Ralith / openxrs

OpenXR bindings for Rust
Apache License 2.0
281 stars 59 forks source link

Action<Posef>::create_space takes a Session instead of a &Session #130

Closed Supreeeme closed 2 months ago

Supreeeme commented 1 year ago

It seems a little counterintuitive for this to consume a session vs just taking a reference to one, like the other Action associated functions.

Ralith commented 1 year ago

Huh? https://github.com/Ralith/openxrs/blob/e5fe4164216fcc16189c52ea58e639e85e8e2d6b/openxr/src/action.rs#L78-L81

Supreeeme commented 1 year ago

https://github.com/Ralith/openxrs/blob/e5fe4164216fcc16189c52ea58e639e85e8e2d6b/openxr/src/action.rs#L82 Why does this take a Session<G> instead of &Session<G>?

Ralith commented 1 year ago

Oh, right, misread. Because it takes ownership of it; if it took a &Session, it'd have to clone internally.

Supreeeme commented 1 year ago

Why does a space need to take ownership of the session? If you want to create more than one space (or do anything with the session after creating the space really) you end up having to clone the session anyway. And looking at the definition for Space::action_from_raw it only uses the inner session handle (which is Copy) so I don't see a reason to consume it.

Ralith commented 1 year ago

Why does a space need to take ownership of the session?

So that the Drop impl can work.

it only uses the inner session handle (which is Copy)

Arc<session::SessionInner> is not Copy.

Supreeeme commented 1 year ago

Which Drop impl are you referring to? The Space Drop impl (actually the Space as a whole) just relies on SessionInner, not Session.

Ralith commented 1 year ago

SessionInner comes from Session. Hence the name.

Supreeeme commented 1 year ago

if it took a &Session, it'd have to clone internally.

Didn't see you say this. Why prefer an external clone? I can't imagine creating a space is the last thing someone wants to do with a session.

zmerp commented 1 year ago

I'd say having Action<Posef>::create_space take a &Session is less surprising because it is symmetric to other parts of the API.

Ralith commented 1 year ago

Fair points; overwhelmingly callers probably don't have short-lived Session values, so providing the ability to move one in isn't likely to be useful. I'd approve a PR making this change.