Skip to content

Conversation

@chenyan2002
Copy link

I have two use cases to call resource::as_ptr() outside of the wit-bindgen module. So making them public but hidden from doc.

Two use cases:

  1. I need a way to convert ResourceBorrow<'a> to &'a Resource. Essentially an owned version of ResourceBorrow::get.
  2. When adding some traits impl to resource types, I need to use rep as an identity to distinguish different resources. I could get around by using get(), but it's more direct to use as_ptr().

@alexcrichton
Copy link
Member

Thanks! For this I'd prefer to have one of (a) leave them private and users use the &-returning methods, or (b) make them public but document them and explain why they might be used. I don't mind either one, but I'd prefer to not be in the current state where they're public-but-hidden as that feels a bit too brittle to me (e.g. easy to forget why they were public in the first place)

@chenyan2002 chenyan2002 changed the title make resource::as_ptr public extend the lifetime of borrowed resource get Nov 8, 2025
@chenyan2002
Copy link
Author

I have a better fix now. The original get function elides the lifetime, so we have fn get(&'b self) -> &'b T. But since Borrow<'a> is valid for the whole 'a duration, we should be able to borrow &'a T instead. The new signature is also semantically more accurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants