Skip to content

Borrowed<'a, T> RFC - #1788

Merged
Ryan Levick (rylev) merged 4 commits into
microsoft:masterfrom
rylev:borrow-rfc
Jun 9, 2022
Merged

Ryan Levick (rylev) merged 4 commits into
microsoft:masterfrom
rylev:borrow-rfc

Conversation

@rylev

@rylev Ryan Levick (rylev) commented May 27, 2022 •

Copy link
Copy Markdown
Contributor

This introduces an RFC for a Borrowed<'a, T> type which models a type that is logically borrowed but still passed by value. As the motivation explains, this is needed to bridge the gap between Rust's ownership semantics and the looser requirements of C and C++.

Introducing this would not only simplify codegen considerably but would also address issues like #1410.

[rendered]

Comment thread rfcs/0002-borrow-type.md Resolved
@ChrisDenton

Chris Denton (ChrisDenton) commented May 27, 2022 •

Copy link
Copy Markdown
Collaborator

Should I/O Safety be mentioned? In particular BorrowedHandle<'a> is essentially the equivalent of:

Borrowed<'a, Win32::Foundation::HANDLE>.

It looks to be nearing stabilization now so I think it would be good to have an interop story, if possible. EDIT: Ah the expanded section on "blittable types" clarifies there is a difference here.

@nrc

Copy link
Copy Markdown

Apologies for the drive-by bikeshedding comment, but since Borrow is a trait in std (with a very different meaning), it is probably a bad name for this type. Borrowed might be good IMO?

@kennykerr

Kenny Kerr (kennykerr) commented May 27, 2022 •

Copy link
Copy Markdown
Collaborator

Since this is the first RFC-style PR, I'll just leave a meta comment that GitHub doesn't have a great markdown review experience. I realize you mitigate the issue with a preview link, but without an easy way to preview the actual content of the PR its less than ideal. The comment granularity also isn't ideal (e.g. large paragraphs). The five minutes I spent with hackmd.io has already spoiled me. 😁

@rylev

Copy link
Copy Markdown
Contributor Author

Since Borrow is a trait in std (with a very different meaning), it is probably a bad name for this type. Borrowed might be good IMO?

This has already been noted in the RFC. We'll definitely want to figure this out before merging.

@Josh015

Copy link
Copy Markdown
Contributor

How about "Loaned"?

Comment thread rfcs/0002-borrow-type.md Resolved
Comment thread rfcs/0002-borrow-type.md Resolved
@rylev

Copy link
Copy Markdown
Contributor Author

I've renamed the type to Borrowed, and added the question of whether an In type alias should be provided.

@rylev Ryan Levick (rylev) changed the title Borrow<'a, T> RFC Borrowed<'a, T> RFC May 31, 2022
Comment thread rfcs/0002-borrow-type.md
fn from(item: &'a IDWriteFontFamily2) -> Self {
// Note: we may want to consider implementing `Deref`
// for COM interfaces so that children can be
// dereferenced into their parents. But this is

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work for COM interface hierarchies (as the memory layout is the same) but not for WinRT interface and class hierarchies. They would still need a param trait or explicit try_into pattern.

@rylev
Ryan Levick (rylev) merged commit 12b0f71 into microsoft:master Jun 9, 2022
@rylev
Ryan Levick (rylev) deleted the borrow-rfc branch June 9, 2022 15:01
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.

5 participants