@@ -347,14 +347,6 @@ I/O safety approach will require changes to Rust code in crates such as
347
347
[ ` RawFd ` ] , though the changes can be made gradually across the ecosystem rather
348
348
than all at once.
349
349
350
- ## New types for ` RawFd ` /` RawHandle ` /` RawSocket `
351
-
352
- Some comments on [ rust-lang/rust #76969 ] suggest introducing new wrappers
353
- around the raw handles. Completely closing the safety loophole would also
354
- require designing new traits, since ` AsRaw* ` doesn't have a way to limit the
355
- lifetime of its return value. This RFC doesn't rule this out, but it would be a
356
- bigger change.
357
-
358
350
## I/O safety but not ` IoSafe `
359
351
360
352
The I/O safety concept doesn't depend on ` IoSafe ` being in ` std ` . Crates could
@@ -374,6 +366,35 @@ it returns raw types, arguably it would be better to make it work more like
374
366
connected to reference lifetimes. If the concept of borrowing is desired, new
375
367
types could be introduced, with better ergonomics, in a separate proposal.
376
368
369
+ ## New types and traits
370
+
371
+ New types and traits could provide a much cleaner API, along the lines of:
372
+
373
+ ``` rust
374
+ pub struct BorrowedFd <'owned > { ... }
375
+ pub struct OwnedFd { ... }
376
+ pub struct OptionFd { ... }
377
+
378
+ pub trait AsBorrowedFd { ... }
379
+ pub trait IntoOwnedFd { ... }
380
+ pub trait FromOwnedFd { ... }
381
+ ```
382
+
383
+ An initial prototype of this here:
384
+
385
+ < https://github.com/sunfishcode/io-experiment >
386
+
387
+ The details are mostly obvious, though one notable aspect of this design is
388
+ the use of ` repr(transparent) ` to define types that can participate in FFI
389
+ directly, leading to FFI usage patterns that don't interact with raw types
390
+ at all. An example of this is here:
391
+
392
+ < https://github.com/sunfishcode/io-experiment/blob/main/examples/hello.rs >
393
+
394
+ This provides a cleaner API than ` *Raw* ` + ` IoSafe ` . The main obvious downside
395
+ is that a lot of code will likely need to continue to support ` *Raw* ` for a
396
+ long time, so this would increase the amount of code they have to maintain.
397
+
377
398
# Prior art
378
399
[ prior-art ] : #prior-art
379
400
0 commit comments