diff options
Diffstat (limited to 'vendor/io-lifetimes')
35 files changed, 7351 insertions, 0 deletions
diff --git a/vendor/io-lifetimes/.cargo-checksum.json b/vendor/io-lifetimes/.cargo-checksum.json new file mode 100644 index 000000000..08c6f8ebe --- /dev/null +++ b/vendor/io-lifetimes/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CODE_OF_CONDUCT.md":"e0bd80144c93b032dadb144d7cf8663c55d697ba2dd60382715c981dfc60e421","COPYRIGHT":"495c30b45120f8af07cfa26eb9cb1ebfe8324560dca2b3b1e76cad1b9b6b489a","Cargo.lock":"dd6a376632f836832953169417d45b477b5050b1e5485830cce175adb68a3358","Cargo.toml":"ec54c49715f8b315addcf954402f37ada2da0a551d247cd9a2789cf7088f9b05","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-Apache-2.0_WITH_LLVM-exception":"268872b9816f90fd8e85db5a28d33f8150ebb8dd016653fb39ef1f94f2686bc5","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","ORG_CODE_OF_CONDUCT.md":"a62b69bf86e605ee1bcbb2f0a12ba79e4cebb6983a7b6491949750aecc4f2178","README.md":"3d07d8badedf6aa11fa8823658c178513ca4c3526328a31491ae1039bfcc0ed1","build.rs":"6b84b29203d9fb618900897dab3a3046967859146c3ec6f8c6ecdd2f6f3a35e7","examples/easy-conversions.rs":"d79a4c39740b842d546f76bfe94a905453730e1c47085d833c21e3903b7874f0","examples/flexible-apis.rs":"c6c9694aa124840e88ca4cb916797f639ac3d35d506f9d7dbc22e44fdbbffe91","examples/hello.rs":"9af2076eefb23e609e9766888404f8b6932ff349ae915617d8e1cfdde3db8b4f","examples/owning-wrapper.rs":"eb03f12c925a15b89aa809c4afaa1fa07ddbaedf09cb8e901e7c2cb5cea9eb00","examples/portable-views.rs":"ff8a9b8391eec5c864dc4fc5f0c80d62d178632f4deb2258ac1188a3a3b2825d","src/example_ffi.rs":"ab0e14396608f5f30cd6a2782413c8661d99ff6dc671eb83a5cf72b9e868d408","src/impls_async_std.rs":"f364a2b6195940723759392d22fd33574c3984f9e7685ef2f36db416ac15a1d6","src/impls_fs_err.rs":"12333298a291377a8c24835c60dfa3338e413e6435576cede04ce780da84ebe6","src/impls_mio.rs":"4defa07ff15012a97f38f373e9a241641c1a0c3db674a3136eca9dd5a50ca54a","src/impls_os_pipe.rs":"96632e7eda41ee2e7fa6cb46b736c10bc671f82716e7b6135286ee224ec5fa31","src/impls_socket2.rs":"2bd87222821955bce8b5c05b438080c0c79a2b69f7f42e0ca41786db3e86c6ef","src/impls_std.rs":"f1c2ebe5c259c3c8ac84b14c62ad63b50fa9f7150417a30cc9b4f1fafa598278","src/impls_std_views.rs":"f6e8737a08e85a9b3be85d606f45221dcc19b5b842b857ab4d6a1e023f453c27","src/impls_tokio.rs":"4f5f3dbdfa9395cd7e5149658cbd3872fa6c3973e1c844b7f6b48ee2e39e9197","src/lib.rs":"1995f551c7ea0535df72ee101ad3887503b92fb99b56b489a37c9f95cdc82685","src/portability.rs":"836b7612cb98a79dfb244d3034e4746b29d0505aac1583ee38da373c8e29f8b3","src/raw.rs":"2fa1ea37da1cc993e36ce7950b3e2bc635b3ac268dacd5b5520e5bfc84741b4a","src/traits.rs":"058dad18da48aba538cf90dd5c93c167b18c53e43423d45028a995380f64c7d1","src/types.rs":"0985f60c8f5e6b1c4851d7b9edb51da48f917ee29501b90a71680aa340f24b85","src/views.rs":"f6eba3976be724ede0fd4e45fed7fae5025e24ced7057955f1e6cf9ce356e116","tests/api.rs":"e04858bd882757a0fc1fd96bea22a3315bb405cf8277dc7e24ff05d93d93fcfd","tests/assumptions.rs":"a743186097cc5715feffad31989f3c115ae59c8e2021ef8fd61298597185731c","tests/ffi.rs":"50817d2a83f69696ecdddcd1eb38a8c9f76dc40b6e324a7c95ebc7f89d1dda8c","tests/niche-optimizations.rs":"bcbdb957e708a1ca475d423c93ca444b9cc8cba432b28da7be094d432110e8c2"},"package":"24c3f4eff5495aee4c0399d7b6a0dc2b6e81be84242ffbfcf253ebacccc1d0cb"}
\ No newline at end of file diff --git a/vendor/io-lifetimes/CODE_OF_CONDUCT.md b/vendor/io-lifetimes/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..b09d258a9 --- /dev/null +++ b/vendor/io-lifetimes/CODE_OF_CONDUCT.md @@ -0,0 +1,49 @@ +# Contributor Covenant Code of Conduct + +*Note*: this Code of Conduct pertains to individuals' behavior. Please also see the [Organizational Code of Conduct][OCoC]. + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Bytecode Alliance CoC team at [report@bytecodealliance.org](mailto:report@bytecodealliance.org). The CoC team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The CoC team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the Bytecode Alliance's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[OCoC]: https://github.com/sunfishcode/io-lifetimes/blob/main/ORG_CODE_OF_CONDUCT.md +[homepage]: https://www.contributor-covenant.org +[version]: https://www.contributor-covenant.org/version/1/4/ diff --git a/vendor/io-lifetimes/COPYRIGHT b/vendor/io-lifetimes/COPYRIGHT new file mode 100644 index 000000000..d8073bdad --- /dev/null +++ b/vendor/io-lifetimes/COPYRIGHT @@ -0,0 +1,29 @@ +Short version for non-lawyers: + +`io-lifetimes` is triple-licensed under Apache 2.0 with the LLVM Exception, +Apache 2.0, and MIT terms. + + +Longer version: + +Copyrights in the `io-lifetimes` project are retained by their contributors. +No copyright assignment is required to contribute to the `io-lifetimes` +project. + +Some files include code derived from Rust's `libstd`; see the comments in +the code for details. + +Except as otherwise noted (below and/or in individual files), `io-lifetimes` +is licensed under: + + - the Apache License, Version 2.0, with the LLVM Exception + <LICENSE-Apache-2.0_WITH_LLVM-exception> or + <http://llvm.org/foundation/relicensing/LICENSE.txt> + - the Apache License, Version 2.0 + <LICENSE-APACHE> or + <http://www.apache.org/licenses/LICENSE-2.0>, + - or the MIT license + <LICENSE-MIT> or + <http://opensource.org/licenses/MIT>, + +at your option. diff --git a/vendor/io-lifetimes/Cargo.lock b/vendor/io-lifetimes/Cargo.lock new file mode 100644 index 000000000..a58b37b90 --- /dev/null +++ b/vendor/io-lifetimes/Cargo.lock @@ -0,0 +1,681 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd8b508d585e01084059b60f06ade4cb7415cd2e4084b71dd1cb44e7d3fb9880" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e18f61464ae81cde0a23e713ae8fd299580c54d697a35820cfd0625b8b0e07" +dependencies = [ + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-lock" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-process" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2c06e30a24e8c78a3987d07f0930edf76ef35e027e7bdb063fccafdad1f60c" +dependencies = [ + "async-io", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "libc", + "once_cell", + "signal-hook", + "winapi", +] + +[[package]] +name = "async-std" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52580991739c5cdb36cde8b2a516371c0a3b70dda36d916cc08b82372916808c" +dependencies = [ + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + +[[package]] +name = "blocking" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + +[[package]] +name = "bumpalo" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "ctor" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "event-listener" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "fs-err" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd79fa345a495d3ae89fb7165fec01c0e72f41821d642dda363a1e97975652e" + +[[package]] +name = "futures-channel" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[package]] +name = "futures-io" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "gloo-timers" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "0.7.2" +dependencies = [ + "async-std", + "fs-err", + "libc", + "mio", + "os_pipe", + "socket2", + "tokio", + "windows-sys", +] + +[[package]] +name = "js-sys" +version = "0.3.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", + "value-bag", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mio" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" + +[[package]] +name = "os_pipe" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c92f2b54f081d635c77e7120862d48db8e91f7f21cef23ab1b4fe9971c59f55" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "polling" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +dependencies = [ + "cfg-if", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "signal-hook" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f392c8f16bda3456c0b00c6de39cb100449b98de55ac41c6cdd2bfcf53a1245" +dependencies = [ + "bytes", + "libc", + "mio", + "once_cell", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "winapi", +] + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "value-bag" +version = "1.0.0-alpha.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" +dependencies = [ + "ctor", + "version_check", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" + +[[package]] +name = "web-sys" +version = "0.3.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/vendor/io-lifetimes/Cargo.toml b/vendor/io-lifetimes/Cargo.toml new file mode 100644 index 000000000..2cc766559 --- /dev/null +++ b/vendor/io-lifetimes/Cargo.toml @@ -0,0 +1,86 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +name = "io-lifetimes" +version = "0.7.2" +authors = ["Dan Gohman <dev@sunfishcode.online>"] +exclude = ["/.github"] +description = "A low-level I/O ownership and borrowing library" +keywords = [ + "api", + "io", +] +categories = [ + "os", + "rust-patterns", +] +license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT" +repository = "https://github.com/sunfishcode/io-lifetimes" + +[dependencies.async-std] +version = "1.9.0" +features = ["unstable"] +optional = true + +[dependencies.fs-err] +version = "2.6.0" +optional = true + +[dependencies.mio] +version = "0.8.0" +features = [ + "net", + "os-ext", +] +optional = true + +[dependencies.socket2] +version = "0.4.0" +optional = true + +[dependencies.tokio] +version = "1.6.0" +features = [ + "io-std", + "fs", + "net", + "process", +] +optional = true + +[features] +close = [ + "libc", + "windows-sys", +] +default = ["close"] + +[target."cfg(not(target_os = \"wasi\"))".dependencies.os_pipe] +version = "1.0.0" +optional = true + +[target."cfg(not(windows))".dependencies.libc] +version = "0.2.96" +optional = true + +[target."cfg(windows)".dependencies.windows-sys] +version = "0.36.0" +features = [ + "Win32_Foundation", + "Win32_Storage_FileSystem", + "Win32_Networking_WinSock", + "Win32_Security", + "Win32_System_IO", + "Win32_System_Threading", +] +optional = true diff --git a/vendor/io-lifetimes/LICENSE-APACHE b/vendor/io-lifetimes/LICENSE-APACHE new file mode 100644 index 000000000..16fe87b06 --- /dev/null +++ b/vendor/io-lifetimes/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/io-lifetimes/LICENSE-Apache-2.0_WITH_LLVM-exception b/vendor/io-lifetimes/LICENSE-Apache-2.0_WITH_LLVM-exception new file mode 100644 index 000000000..f9d81955f --- /dev/null +++ b/vendor/io-lifetimes/LICENSE-Apache-2.0_WITH_LLVM-exception @@ -0,0 +1,220 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +--- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + diff --git a/vendor/io-lifetimes/LICENSE-MIT b/vendor/io-lifetimes/LICENSE-MIT new file mode 100644 index 000000000..31aa79387 --- /dev/null +++ b/vendor/io-lifetimes/LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/vendor/io-lifetimes/ORG_CODE_OF_CONDUCT.md b/vendor/io-lifetimes/ORG_CODE_OF_CONDUCT.md new file mode 100644 index 000000000..6f4fb3f53 --- /dev/null +++ b/vendor/io-lifetimes/ORG_CODE_OF_CONDUCT.md @@ -0,0 +1,143 @@ +# Bytecode Alliance Organizational Code of Conduct (OCoC) + +*Note*: this Code of Conduct pertains to organizations' behavior. Please also see the [Individual Code of Conduct](CODE_OF_CONDUCT.md). + +## Preamble + +The Bytecode Alliance (BA) welcomes involvement from organizations, +including commercial organizations. This document is an +*organizational* code of conduct, intended particularly to provide +guidance to commercial organizations. It is distinct from the +[Individual Code of Conduct (ICoC)](CODE_OF_CONDUCT.md), and does not +replace the ICoC. This OCoC applies to any group of people acting in +concert as a BA member or as a participant in BA activities, whether +or not that group is formally incorporated in some jurisdiction. + +The code of conduct described below is not a set of rigid rules, and +we did not write it to encompass every conceivable scenario that might +arise. For example, it is theoretically possible there would be times +when asserting patents is in the best interest of the BA community as +a whole. In such instances, consult with the BA, strive for +consensus, and interpret these rules with an intent that is generous +to the community the BA serves. + +While we may revise these guidelines from time to time based on +real-world experience, overall they are based on a simple principle: + +*Bytecode Alliance members should observe the distinction between + public community functions and private functions — especially + commercial ones — and should ensure that the latter support, or at + least do not harm, the former.* + +## Guidelines + + * **Do not cause confusion about Wasm standards or interoperability.** + + Having an interoperable WebAssembly core is a high priority for + the BA, and members should strive to preserve that core. It is fine + to develop additional non-standard features or APIs, but they + should always be clearly distinguished from the core interoperable + Wasm. + + Treat the WebAssembly name and any BA-associated names with + respect, and follow BA trademark and branding guidelines. If you + distribute a customized version of software originally produced by + the BA, or if you build a product or service using BA-derived + software, use names that clearly distinguish your work from the + original. (You should still provide proper attribution to the + original, of course, wherever such attribution would normally be + given.) + + Further, do not use the WebAssembly name or BA-associated names in + other public namespaces in ways that could cause confusion, e.g., + in company names, names of commercial service offerings, domain + names, publicly-visible social media accounts or online service + accounts, etc. It may sometimes be reasonable, however, to + register such a name in a new namespace and then immediately donate + control of that account to the BA, because that would help the project + maintain its identity. + + For further guidance, see the BA Trademark and Branding Policy + [TODO: create policy, then insert link]. + + * **Do not restrict contributors.** If your company requires + employees or contractors to sign non-compete agreements, those + agreements must not prevent people from participating in the BA or + contributing to related projects. + + This does not mean that all non-compete agreements are incompatible + with this code of conduct. For example, a company may restrict an + employee's ability to solicit the company's customers. However, an + agreement must not block any form of technical or social + participation in BA activities, including but not limited to the + implementation of particular features. + + The accumulation of experience and expertise in individual persons, + who are ultimately free to direct their energy and attention as + they decide, is one of the most important drivers of progress in + open source projects. A company that limits this freedom may hinder + the success of the BA's efforts. + + * **Do not use patents as offensive weapons.** If any BA participant + prevents the adoption or development of BA technologies by + asserting its patents, that undermines the purpose of the + coalition. The collaboration fostered by the BA cannot include + members who act to undermine its work. + + * **Practice responsible disclosure** for security vulnerabilities. + Use designated, non-public reporting channels to disclose technical + vulnerabilities, and give the project a reasonable period to + respond, remediate, and patch. [TODO: optionally include the + security vulnerability reporting URL here.] + + Vulnerability reporters may patch their company's own offerings, as + long as that patching does not significantly delay the reporting of + the vulnerability. Vulnerability information should never be used + for unilateral commercial advantage. Vendors may legitimately + compete on the speed and reliability with which they deploy + security fixes, but withholding vulnerability information damages + everyone in the long run by risking harm to the BA project's + reputation and to the security of all users. + + * **Respect the letter and spirit of open source practice.** While + there is not space to list here all possible aspects of standard + open source practice, some examples will help show what we mean: + + * Abide by all applicable open source license terms. Do not engage + in copyright violation or misattribution of any kind. + + * Do not claim others' ideas or designs as your own. + + * When others engage in publicly visible work (e.g., an upcoming + demo that is coordinated in a public issue tracker), do not + unilaterally announce early releases or early demonstrations of + that work ahead of their schedule in order to secure private + advantage (such as marketplace advantage) for yourself. + + The BA reserves the right to determine what constitutes good open + source practices and to take action as it deems appropriate to + encourage, and if necessary enforce, such practices. + +## Enforcement + +Instances of organizational behavior in violation of the OCoC may +be reported by contacting the Bytecode Alliance CoC team at +[report@bytecodealliance.org](mailto:report@bytecodealliance.org). The +CoC team will review and investigate all complaints, and will respond +in a way that it deems appropriate to the circumstances. The CoC team +is obligated to maintain confidentiality with regard to the reporter of +an incident. Further details of specific enforcement policies may be +posted separately. + +When the BA deems an organization in violation of this OCoC, the BA +will, at its sole discretion, determine what action to take. The BA +will decide what type, degree, and duration of corrective action is +needed, if any, before a violating organization can be considered for +membership (if it was not already a member) or can have its membership +reinstated (if it was a member and the BA canceled its membership due +to the violation). + +In practice, the BA's first approach will be to start a conversation, +with punitive enforcement used only as a last resort. Violations +often turn out to be unintentional and swiftly correctable with all +parties acting in good faith. diff --git a/vendor/io-lifetimes/README.md b/vendor/io-lifetimes/README.md new file mode 100644 index 000000000..3db3d3c36 --- /dev/null +++ b/vendor/io-lifetimes/README.md @@ -0,0 +1,196 @@ +<div align="center"> + <h1><code>io-lifetimes</code></h1> + + <p> + <strong>A low-level I/O ownership and borrowing library</strong> + </p> + + <p> + <a href="https://github.com/sunfishcode/io-lifetimes/actions?query=workflow%3ACI"><img src="https://github.com/sunfishcode/io-lifetimes/workflows/CI/badge.svg" alt="Github Actions CI Status" /></a> + <a href="https://crates.io/crates/io-lifetimes"><img src="https://img.shields.io/crates/v/io-lifetimes.svg" alt="crates.io page" /></a> + <a href="https://docs.rs/io-lifetimes"><img src="https://docs.rs/io-lifetimes/badge.svg" alt="docs.rs docs" /></a> + </p> +</div> + +This library introduces `OwnedFd`, `BorrowedFd`, and supporting types and +traits, and corresponding features for Windows, which implement safe owning +and borrowing I/O lifetime patterns. + +This is associated with [RFC 3128], the I/O Safety RFC, which is now merged. +Work is now underway to move the `OwnedFd` and `BorrowedFd` types and `AsFd` +trait developed here into `std`. + +Some features currently require nightly Rust, as they depend on `rustc_attrs` +to perform niche optimizations needed for FFI use cases. + +For a quick taste, check out the code examples: + + - [hello], a basic demo of this API, doing low-level I/O manually, using the + [provided example FFI bindings] + - [easy-conversions], demonstrating the `from_into` convenience feature for + converting from an `impl Into*` into an `impl From*`. + - [portable-views], demonstrating the convenience feature which allows one + to temporarily "view" a file descriptor as any owning type such as `File` + - [flexible-apis], demonstrating how to write library APIs that accept + untyped I/O resources. + - [owning-wrapper], demonstrating how to implement a type which wraps an + `Owned*` type. + +[hello]: https://github.com/sunfishcode/io-lifetimes/blob/main/examples/hello.rs +[easy-conversions]: https://github.com/sunfishcode/io-lifetimes/blob/main/examples/easy-conversions.rs +[portable-views]: https://github.com/sunfishcode/io-lifetimes/blob/main/examples/portable-views.rs +[flexible-apis]: https://github.com/sunfishcode/io-lifetimes/blob/main/examples/flexible-apis.rs +[owning-wrapper]: https://github.com/sunfishcode/io-lifetimes/blob/main/examples/owning-wrapper.rs +[provided example FFI bindings]: https://github.com/sunfishcode/io-lifetimes/blob/main/src/example_ffi.rs + +The core of the API is very simple, and consists of two main types and three +main traits: + +```rust +pub struct BorrowedFd<'fd> { ... } +pub struct OwnedFd { ... } + +pub trait AsFd { ... } +pub trait IntoFd { ... } +pub trait FromFd { ... } + +impl AsRawFd for BorrowedFd<'_> { ... } +impl AsRawFd for OwnedFd { ... } +impl IntoRawFd for OwnedFd { ... } +impl FromRawFd for OwnedFd { ... } + +impl Drop for OwnedFd { ... } + +impl AsFd for BorrowedFd<'_> { ... } +impl AsFd for OwnedFd { ... } +impl IntoFd for OwnedFd { ... } +impl FromFd for OwnedFd { ... } +``` + +On Windows, there are `Handle` and `Socket` versions of every `Fd` thing, and +a special `HandleOrInvalid` type to cope with inconsistent error reporting +in the Windows API. + +## The magic of transparency + +Here's the fun part. `BorrowedFd` and `OwnedFd` are `repr(transparent)` and +hold `RawFd` values, and `Option<BorrowedFd>` and `Option<OwnedFd>` are +FFI-safe (on nightly Rust), so they can all be used in FFI [directly]: + +[directly]: https://github.com/sunfishcode/io-lifetimes/blob/main/src/example_ffi.rs + +```rust +extern "C" { + pub fn open(pathname: *const c_char, flags: c_int, ...) -> Option<OwnedFd>; + pub fn read(fd: BorrowedFd<'_>, ptr: *mut c_void, size: size_t) -> ssize_t; + pub fn write(fd: BorrowedFd<'_>, ptr: *const c_void, size: size_t) -> ssize_t; + pub fn close(fd: OwnedFd) -> c_int; +} +``` + +With bindings like this, users never have to touch `RawFd` values. Of course, +not all code will do this, but it is a fun feature for code that can. This +is what motivates having `BorrowedFd` instead of just using `&OwnedFd`. + +Note the use of `Option<OwnedFd>` as the return value of `open`, representing +the fact that it can either succeed or fail. + +## I/O Safety in Rust Nightly + +The I/O Safety +[implementation PR](https://github.com/rust-lang/rust/pull/87329) has now +landed and is available on Rust Nightly. It can be used directly, or through +io-lifetimes: when `io_lifetimes_use_std` mode is enabled, io-lifetimes uses +the std's `OwnedFd`, `BorrowedFd`, and `AsFd` instead of defining its own. + +To enable `io_lifetimes_use_std` mode: + - Set the environment variable `RUSTFLAGS=--cfg=io_lifetimes_use_std`, and + - add `#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]` to your + lib.rs or main.rs. + +Note that, unfortunately, `io_lifetimes_use_std` mode doesn't support the +optional impls for third-party crates. + +The code in `std` uses `From<OwnedFd>` and `Into<OwnedFd>` instead of `FromFd` +and `IntoFd`. io-lifetimes is unable to provide impls for these for third-party +types, so it continues to provide `FromFd` and `IntoFd` for now, with default +impls that forward to `From<OwnedFd>` and `Into<OwnedFd>` in +`io_lifetimes_use_std` mode. + +io-lifetimes also includes several features which are not (yet?) in std, +including the portability traits `AsFilelike`/`AsSocketlike`/etc., the +`from_into_*` functions in the `From*` traits, and [views]. + +If you test a crate with the std I/O safety types and traits, or io-lifetimes +in `io_lifetimes_use_std` mode, please post a note about it in the +[I/O safety tracking issue] as an example of usage. + +[I/O safety tracking issue]: https://github.com/rust-lang/rust/issues/87074 +[views]: https://docs.rs/io-lifetimes/*/io_lifetimes/views/index.html + +## Prior Art + +There are several similar crates: [fd](https://crates.io/crates/fd), +[filedesc](https://crates.io/crates/filedesc), +[filedescriptor](https://crates.io/crates/filedescriptor), +[owned-fd](https://crates.io/crates/owned-fd), and +[unsafe-io](https://crates.io/crates/unsafe-io). + +Some of these provide additional features such as the ability to create pipes +or sockets, to get and set flags, and to do read and write operations. +io-lifetimes omits these features, leaving them to to be provided as separate +layers on top. + +Most of these crates provide ways to duplicate a file descriptor. io-lifetimes +currently treats this as another feature that can be provided by a layer on +top, though if there are use cases where this is a common operation, it could +be added. + +io-lifetimes's distinguishing features are its use of `repr(transparent)` +to support direct FFI usage, niche optimizations so `Option` can support direct +FFI usafe as well (on nightly Rust), lifetime-aware `As*`/`Into*`/`From*` +traits which leverage Rust's lifetime system and allow safe and checked +`from_*` and `as_*`/`into_*` functions, and powerful convenience features +enabled by its underlying safety. + +io-lifetimes also has full Windows support, as well as Unix/Windows +portability abstractions, covering both file-like and socket-like types. + +io-lifetimes's [`OwnedFd`] type is similar to +[fd](https://crates.io/crates/fd)'s +[`FileDesc`](https://docs.rs/fd/0.2.3/fd/struct.FileDesc.html). io-lifetimes +doesn't have a `close_on_drop` parameter, and instead uses [`OwnedFd`] and +[`BorrowedFd`] to represent dropping and non-dropping handles, respectively, in +a way that is checked at compile time rather than runtime. + +io-lifetimes's [`OwnedFd`] type is also similar to +[filedesc](https://crates.io/crates/filedesc)'s +[`FileDesc`](https://docs.rs/filedesc/0.3.0/filedesc/struct.FileDesc.html) +io-lifetimes's `OwnedFd` reserves the value -1, so it doesn't need to test for +`-1` in its `Drop`, and `Option<OwnedFd>` (on nightly Rust) is the same size +as `FileDesc`. + +io-lifetimes's [`OwnedFd`] type is also similar to +[owned-fd](https://crates.io/crates/owned-fd)'s +[`OwnedFd`](https://docs.rs/owned-fd/0.1.0/owned_fd/struct.OwnedFd.html). +io-lifetimes doesn't implement `Clone`, because duplicating a file descriptor +can fail due to OS process limits, while `Clone` is an infallible interface. + +io-lifetimes's [`BorrowedFd`] is similar to +[owned-fd](https://crates.io/crates/owned-fd)'s +[`FdRef`](https://docs.rs/owned-fd/0.1.0/owned_fd/struct.FdRef.html), except it +uses a lifetime parameter and `PhantomData` rather than transmuting a raw file +descriptor value into a reference value. + +io-lifetimes's convenience features are similar to those of +[unsafe-io](https://crates.io/crates/unsafe-io), but io-lifetimes is built on +its own `As*`/`Into*`/`From*` traits, rather than extending +`AsRaw*`/`IntoRaw*`/`FromRaw*` with +[`OwnsRaw`](https://docs.rs/unsafe-io/0.6.9/unsafe_io/trait.OwnsRaw.html), so +they're simpler and safer to use. io-lifetimes doesn't include unsafe-io's +`*ReadWrite*` or `*HandleOrSocket*` abstractions, and leaves these as features +to be provided by separate layers on top. + +[`OwnedFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/struct.OwnedFd.html +[`BorrowedFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/struct.BorrowedFd.html +[RFC 3128]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md diff --git a/vendor/io-lifetimes/build.rs b/vendor/io-lifetimes/build.rs new file mode 100644 index 000000000..81026863f --- /dev/null +++ b/vendor/io-lifetimes/build.rs @@ -0,0 +1,67 @@ +use std::env::var; +use std::io::Write; + +fn main() { + // Niche optimizations for `Borrowed*` and `Owned*` depend on `rustc_attrs` + // which, outside of `std`, are only available on nightly. + use_feature_or_nothing("rustc_attrs"); + + // Rust 1.56 and earlier don't support panic in const fn. + if has_panic_in_const_fn() { + use_feature("panic_in_const_fn") + } + + // Don't rerun this on changes other than build.rs, as we only depend on + // the rustc version. + println!("cargo:rerun-if-changed=build.rs"); +} + +fn use_feature_or_nothing(feature: &str) { + if has_feature(feature) { + use_feature(feature); + } +} + +fn use_feature(feature: &str) { + println!("cargo:rustc-cfg={}", feature); +} + +/// Test whether the rustc at `var("RUSTC")` supports the given feature. +fn has_feature(feature: &str) -> bool { + let out_dir = var("OUT_DIR").unwrap(); + let rustc = var("RUSTC").unwrap(); + + let mut child = std::process::Command::new(rustc) + .arg("--crate-type=rlib") // Don't require `main`. + .arg("--emit=metadata") // Do as little as possible but still parse. + .arg("--out-dir") + .arg(out_dir) // Put the output somewhere inconsequential. + .arg("-") // Read from stdin. + .stdin(std::process::Stdio::piped()) // Stdin is a pipe. + .spawn() + .unwrap(); + + writeln!(child.stdin.take().unwrap(), "#![feature({})]", feature).unwrap(); + + child.wait().unwrap().success() +} + +/// Test whether the rustc at `var("RUSTC")` supports panic in `const fn`. +fn has_panic_in_const_fn() -> bool { + let out_dir = var("OUT_DIR").unwrap(); + let rustc = var("RUSTC").unwrap(); + + let mut child = std::process::Command::new(rustc) + .arg("--crate-type=rlib") // Don't require `main`. + .arg("--emit=metadata") // Do as little as possible but still parse. + .arg("--out-dir") + .arg(out_dir) // Put the output somewhere inconsequential. + .arg("-") // Read from stdin. + .stdin(std::process::Stdio::piped()) // Stdin is a pipe. + .spawn() + .unwrap(); + + writeln!(child.stdin.take().unwrap(), "const fn foo() {{ panic!() }}").unwrap(); + + child.wait().unwrap().success() +} diff --git a/vendor/io-lifetimes/examples/easy-conversions.rs b/vendor/io-lifetimes/examples/easy-conversions.rs new file mode 100644 index 000000000..87481c12f --- /dev/null +++ b/vendor/io-lifetimes/examples/easy-conversions.rs @@ -0,0 +1,30 @@ +//! io-lifetimes provides safe, portable, and convenient conversions from types +//! implementing `IntoFilelike` and `FromSocketlike` to types implementing +//! `FromFilelike` and `IntoSocketlike`, respectively. + +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +use io_lifetimes::FromFilelike; +use std::fs::File; +use std::io::{self, Read}; +use std::process::{Command, Stdio}; + +fn main() -> io::Result<()> { + let mut child = Command::new("cargo") + .arg("--help") + .stdout(Stdio::piped()) + .spawn() + .expect("failed to execute child"); + + // Convert from `ChildStderr` into `File` without any platform-specific + // code or `unsafe`! + let mut file = File::from_into_filelike(child.stdout.take().unwrap()); + + // Well, this example is not actually that cool, because `File` doesn't let + // you do anything that you couldn't already do with `ChildStderr` etc., but + // it's useful outside of standard library types. + let mut buffer = String::new(); + file.read_to_string(&mut buffer)?; + + Ok(()) +} diff --git a/vendor/io-lifetimes/examples/flexible-apis.rs b/vendor/io-lifetimes/examples/flexible-apis.rs new file mode 100644 index 000000000..8eb19a287 --- /dev/null +++ b/vendor/io-lifetimes/examples/flexible-apis.rs @@ -0,0 +1,108 @@ +//! io-lifetimes provides two different options for library authors +//! writing APIs which accept untyped I/O resources. +//! +//! The following uses the POSIX-ish `Fd` types; similar considerations +//! apply to the Windows and portable types. + +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +#[cfg(all(feature = "close", not(windows)))] +use io_lifetimes::{AsFd, BorrowedFd, IntoFd, OwnedFd}; + +/// The simplest way to accept a borrowed I/O resource is to simply use a +/// `BorrwedFd` as an argument. This doesn't require the function to have any +/// type parameters. It also works in FFI signatures, as `BorrowedFd` and (on +/// Rust nightly) `Option<BorrowedFd>` are guaranteed to have the same layout +/// as `RawFd`. +/// +/// Callers with an `AsFd`-implementing type would call `.as_fd()` and pass +/// the result. +#[cfg(all(feature = "close", not(windows)))] +fn use_fd_a(fd: BorrowedFd<'_>) { + let _ = fd; +} + +/// Another way to do this is to use an `AsFd` type parameter. This is more +/// verbose at the function definition site, and entails monomorphization, but +/// it has the advantage of allowing users to pass in any type implementing +/// `AsFd` directly, without having to call `.as_fd()` themselves. +#[cfg(all(feature = "close", not(windows)))] +fn use_fd_b<Fd: AsFd>(fd: Fd) { + let _ = fd.as_fd(); +} + +/// Another way to do this is to use an `impl AsFd` parameter. +#[cfg(all(feature = "close", not(windows)))] +fn use_fd_c(fd: impl AsFd) { + let _ = fd.as_fd(); +} + +/// The simplest way to accept a consumed I/O resource is to simply use an +/// `OwnedFd` as an argument. Similar to `use_fd_a`, this doesn't require the +/// function to have any type parameters, and also works in FFI signatures. +/// +/// Callers with an `IntoFd`-implementing type would call `.into_fd()` and pass +/// the result. +#[cfg(all(feature = "close", not(windows)))] +fn consume_fd_a(fd: OwnedFd) { + let _ = fd; +} + +/// Another way to do this is to use an `IntoFd` type parameter. Similar to +/// `use_fd_b`, this is more verbose here and entails monomorphization, but it +/// has the advantage of allowing users to pass in any type implementing +/// `IntoFd` directly. +#[cfg(all(feature = "close", not(windows)))] +fn consume_fd_b<Fd: IntoFd>(fd: Fd) { + let _ = fd.into_fd(); +} + +/// Another way to do this is to use an `impl IntoFd` parameter. +#[cfg(all(feature = "close", not(windows)))] +fn consume_fd_c(fd: impl IntoFd) { + let _ = fd.into_fd(); +} + +/// Now let's see how the APIs look for users. +#[cfg(all(feature = "close", not(windows)))] +fn main() { + let f = std::fs::File::open("Cargo.toml").unwrap(); + + // The simple option requires an `.as_fd()` at the callsite. + use_fd_a(f.as_fd()); + + // Another option can take a reference to any owning type directly. + use_fd_b(&f); + + // Of course, users can still pass in `BorrowedFd` values if they want to. + use_fd_b(f.as_fd()); + + // The other option is `impl AsFd`. + use_fd_c(&f); + + // Users can still pass in `BorrowedFd` values if they want to here too. + use_fd_c(f.as_fd()); + + let a = std::fs::File::open("Cargo.toml").unwrap(); + let b = std::fs::File::open("Cargo.toml").unwrap(); + let c = std::fs::File::open("Cargo.toml").unwrap(); + + // The simple option requires an `.into_fd()` at the callsite. + consume_fd_a(a.into_fd()); + + // Another option can take any `IntoFd` type directly. + consume_fd_b(b); + + // The other option can take any `IntoFd` type directly. + consume_fd_c(c); +} + +#[cfg(windows)] +fn main() { + println!("This example uses non-Windows APIs."); +} + +#[cfg(all(not(feature = "close"), not(windows)))] +fn main() { + println!("This example requires the \"close\" feature."); +} diff --git a/vendor/io-lifetimes/examples/hello.rs b/vendor/io-lifetimes/examples/hello.rs new file mode 100644 index 000000000..4f6b1a4ed --- /dev/null +++ b/vendor/io-lifetimes/examples/hello.rs @@ -0,0 +1,129 @@ +//! A simple testcase that prints a few messages to the console, demonstrating +//! the io-lifetimes API. + +#![cfg_attr(not(rustc_attrs), allow(unused_imports))] +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +#[cfg(feature = "close")] +use io_lifetimes::example_ffi::*; +#[cfg(feature = "close")] +use std::{ + fs::File, + io::{self, Write}, +}; + +#[cfg(all(unix, feature = "close"))] +use io_lifetimes::{AsFd, FromFd, OwnedFd}; + +#[cfg(windows)] +use io_lifetimes::{AsHandle, FromHandle, OwnedHandle}; +#[cfg(windows)] +use std::{convert::TryInto, os::windows::io::RawHandle, ptr::null_mut}; + +#[cfg(all(rustc_attrs, unix, feature = "close"))] +fn main() -> io::Result<()> { + let fd = unsafe { + // Open a file, which returns an `Option<OwnedFd>`, which we can + // maybe convert into an `OwnedFile`. + let fd: OwnedFd = open("/dev/stdout\0".as_ptr() as *const _, O_WRONLY | O_CLOEXEC) + .ok_or_else(io::Error::last_os_error)?; + + // Borrow the fd to write to it. + let result = write(fd.as_fd(), "hello, world\n".as_ptr() as *const _, 13); + match result { + -1 => return Err(io::Error::last_os_error()), + 13 => (), + _ => return Err(io::Error::new(io::ErrorKind::Other, "short write")), + } + + fd + }; + + // Convert into a `File`. No `unsafe` here! + let mut file = File::from_fd(fd); + writeln!(&mut file, "greetings, y'all")?; + + // We can borrow a `BorrowedFd` from a `File`. + unsafe { + let result = write(file.as_fd(), "sup?\n".as_ptr() as *const _, 5); + match result { + -1 => return Err(io::Error::last_os_error()), + 5 => (), + _ => return Err(io::Error::new(io::ErrorKind::Other, "short write")), + } + } + + // `OwnedFd` closes the fd in its `Drop` implementation. + + Ok(()) +} + +/// The Windows analog of the above. +#[cfg(all(windows, feature = "close"))] +fn main() -> io::Result<()> { + let handle = unsafe { + // Open a file, which returns an `HandleOrInvalid`, which we can fallibly + // convert into an `OwnedFile`. + let handle: OwnedHandle = CreateFileW( + ['C' as u16, 'O' as _, 'N' as _, 0].as_ptr(), + FILE_GENERIC_WRITE, + 0, + null_mut(), + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + null_mut() as RawHandle as HANDLE, + ) + .try_into() + .map_err(|_err| io::Error::last_os_error())?; + + // Borrow the handle to write to it. + let mut number_of_bytes_written = 0; + let result = WriteFile( + handle.as_handle(), + "hello, world\n".as_ptr() as *const _, + 13, + &mut number_of_bytes_written, + null_mut(), + ); + match (result, number_of_bytes_written) { + (0, _) => return Err(io::Error::last_os_error()), + (_, 13) => (), + (_, _) => return Err(io::Error::new(io::ErrorKind::Other, "short write")), + } + + handle + }; + + // Convert into a `File`. No `unsafe` here! + let mut file = File::from_handle(handle); + writeln!(&mut file, "greetings, y'all")?; + + // We can borrow a `BorrowedHandle` from a `File`. + unsafe { + let mut number_of_bytes_written = 0; + let result = WriteFile( + file.as_handle(), + "sup?\n".as_ptr() as *const _, + 5, + &mut number_of_bytes_written, + null_mut(), + ); + match (result, number_of_bytes_written) { + (0, _) => return Err(io::Error::last_os_error()), + (_, 5) => (), + (_, _) => return Err(io::Error::new(io::ErrorKind::Other, "short write")), + } + } + + // `OwnedHandle` closes the handle in its `Drop` implementation. + + Ok(()) +} + +#[cfg(all( + not(all(rustc_attrs, unix, feature = "close")), + not(all(windows, feature = "close")) +))] +fn main() { + println!("On Unix, this example requires Rust nightly (for `rustc_attrs`) and the \"close\" feature."); +} diff --git a/vendor/io-lifetimes/examples/owning-wrapper.rs b/vendor/io-lifetimes/examples/owning-wrapper.rs new file mode 100644 index 000000000..74a05b2f4 --- /dev/null +++ b/vendor/io-lifetimes/examples/owning-wrapper.rs @@ -0,0 +1,147 @@ +//! A simple example implementing the main traits for a type. + +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +use io_lifetimes::OwnedFilelike; +#[cfg(not(windows))] +use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; + +/// A wrapper around a file descriptor. +/// +/// Implementing `AsFd`, `IntoFd`, and `FromFd` for a type that wraps an +/// `Owned*` is straightforward. `Owned*` types also automatically close the +/// handle in its `Drop`. +/// +/// Should owning wrappers implement `AsRawFd`, `IntoRawFd`, and `FromRawFd` +/// too? They can, and there's no need to remove them from a type that already +/// implements them. But for new code, they can be omitted. Users that really +/// need the raw value can always do `as_fd().as_raw_fd()`, +/// `.into_fd().into_raw_fd()`, or `T::from_fd(OwnedFd::from_raw_fd(raw_fd))`. +/// But if possible, users should use just `as_fd`, `into_fd`, and `from_fd` +/// and avoid working with raw values altogether. +struct Thing { + filelike: OwnedFilelike, +} + +#[cfg(not(windows))] +impl AsFd for Thing { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + self.filelike.as_fd() + } +} + +#[cfg(not(windows))] +impl IntoFd for Thing { + #[inline] + fn into_fd(self) -> OwnedFd { + self.filelike + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(windows))] +impl From<Thing> for OwnedFd { + #[inline] + fn from(owned: Thing) -> Self { + owned.filelike + } +} + +#[cfg(not(windows))] +impl FromFd for Thing { + #[inline] + fn from_fd(filelike: OwnedFd) -> Self { + Self { filelike } + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(not(windows))] +impl From<OwnedFd> for Thing { + #[inline] + fn from(filelike: OwnedFd) -> Self { + Self { filelike } + } +} + +#[cfg(windows)] +impl AsHandle for Thing { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + self.filelike.as_handle() + } +} + +#[cfg(windows)] +impl IntoHandle for Thing { + #[inline] + fn into_handle(self) -> OwnedHandle { + self.filelike + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +impl From<Thing> for OwnedHandle { + #[inline] + fn from(owned: Thing) -> Self { + owned.filelike + } +} + +#[cfg(windows)] +impl FromHandle for Thing { + #[inline] + fn from_handle(filelike: OwnedHandle) -> Self { + Self { filelike } + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +impl From<OwnedHandle> for Thing { + #[inline] + fn from(filelike: OwnedHandle) -> Self { + Self { filelike } + } +} + +#[cfg(feature = "close")] +fn main() { + use io_lifetimes::{AsFilelike, FromFilelike, IntoFilelike}; + + // Minimally exercise `Thing`'s Posix-ish API. + #[cfg(not(windows))] + { + let file = std::fs::File::open("Cargo.toml").unwrap(); + let thing = Thing::from_into_fd(file); + let _ = thing.as_fd(); + let _ = thing.into_fd(); + } + + // Minimally exercise `Thing`'s Windows API. + #[cfg(windows)] + { + let file = std::fs::File::open("Cargo.toml").unwrap(); + let thing = Thing::from_into_handle(file); + let _ = thing.as_handle(); + let _ = thing.into_handle(); + } + + // Implementing the above traits makes the blanket impls for the portable + // `Filelike` traits available too. + { + let file = std::fs::File::open("Cargo.toml").unwrap(); + let thing = Thing::from_into_filelike(file); + let _ = thing.as_filelike(); + let _ = thing.into_filelike(); + } +} + +#[cfg(not(feature = "close"))] +fn main() { + println!("This example requires the \"close\" feature."); +} diff --git a/vendor/io-lifetimes/examples/portable-views.rs b/vendor/io-lifetimes/examples/portable-views.rs new file mode 100644 index 000000000..410b4c2f0 --- /dev/null +++ b/vendor/io-lifetimes/examples/portable-views.rs @@ -0,0 +1,28 @@ +//! io-lifetimes provides safe, convenient, and portable ways to temporarily +//! view an I/O resource as a `File`, `Socket`, or other types. + +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +use io_lifetimes::AsFilelike; +use std::fs::File; +use std::io::{self, stdout}; + +fn main() -> io::Result<()> { + let stdout = stdout(); + + // With `AsFilelike`, any type implementing `AsFd`/`AsHandle` can be viewed + // as any type supporting `FromFilelike`, so you can call `File` methods on + // `Stdout` or other things. + // + // Whether or not you can actually do this is up to the OS, of course. In + // this case, Unix can do this, but it appears Windows can't. + let metadata = stdout.as_filelike_view::<File>().metadata()?; + + if metadata.is_file() { + println!("stdout is a file!"); + } else { + println!("stdout is not a file!"); + } + + Ok(()) +} diff --git a/vendor/io-lifetimes/src/example_ffi.rs b/vendor/io-lifetimes/src/example_ffi.rs new file mode 100644 index 000000000..8f7c238ba --- /dev/null +++ b/vendor/io-lifetimes/src/example_ffi.rs @@ -0,0 +1,75 @@ +//! This is just a sample of what FFI using this crate can look like. + +#![cfg_attr(not(rustc_attrs), allow(unused_imports))] +#![allow(missing_docs)] + +#[cfg(any(unix, target_os = "wasi"))] +use crate::{BorrowedFd, OwnedFd}; +#[cfg(windows)] +use crate::{BorrowedHandle, HandleOrInvalid}; + +#[cfg(any(unix, target_os = "wasi"))] +use libc::{c_char, c_int, c_void, size_t, ssize_t}; +#[cfg(windows)] +use { + core::ffi::c_void, + windows_sys::core::PCWSTR, + windows_sys::Win32::Foundation::BOOL, + windows_sys::Win32::Security::SECURITY_ATTRIBUTES, + windows_sys::Win32::Storage::FileSystem::{ + FILE_ACCESS_FLAGS, FILE_CREATION_DISPOSITION, FILE_FLAGS_AND_ATTRIBUTES, FILE_SHARE_MODE, + }, + windows_sys::Win32::System::IO::OVERLAPPED, +}; + +// Declare a few FFI functions ourselves, to show off the FFI ergonomics. +#[cfg(all(rustc_attrs, any(unix, target_os = "wasi")))] +extern "C" { + pub fn open(pathname: *const c_char, flags: c_int, ...) -> Option<OwnedFd>; +} +#[cfg(any(unix, target_os = "wasi"))] +extern "C" { + pub fn read(fd: BorrowedFd<'_>, ptr: *mut c_void, size: size_t) -> ssize_t; + pub fn write(fd: BorrowedFd<'_>, ptr: *const c_void, size: size_t) -> ssize_t; +} +#[cfg(any(unix, target_os = "wasi"))] +pub use libc::{O_CLOEXEC, O_CREAT, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}; + +// The Windows analogs of the above. Note the use of [`HandleOrInvalid`] as +// the return type for `CreateFileW`, since that function is defined to return +// [`INVALID_HANDLE_VALUE`] on error instead of null. +#[cfg(windows)] +extern "system" { + pub fn CreateFileW( + lpfilename: PCWSTR, + dwdesiredaccess: FILE_ACCESS_FLAGS, + dwsharemode: FILE_SHARE_MODE, + lpsecurityattributes: *const SECURITY_ATTRIBUTES, + dwcreationdisposition: FILE_CREATION_DISPOSITION, + dwflagsandattributes: FILE_FLAGS_AND_ATTRIBUTES, + htemplatefile: HANDLE, + ) -> HandleOrInvalid; + pub fn ReadFile( + hfile: BorrowedHandle<'_>, + lpbuffer: *mut c_void, + nnumberofbytestoread: u32, + lpnumberofbytesread: *mut u32, + lpoverlapped: *mut OVERLAPPED, + ) -> BOOL; + pub fn WriteFile( + hfile: BorrowedHandle<'_>, + lpbuffer: *const c_void, + nnumberofbytestowrite: u32, + lpnumberofbyteswritten: *mut u32, + lpoverlapped: *mut OVERLAPPED, + ) -> BOOL; +} + +#[cfg(windows)] +pub use { + windows_sys::Win32::Foundation::HANDLE, + windows_sys::Win32::Storage::FileSystem::{ + CREATE_ALWAYS, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, FILE_GENERIC_READ, FILE_GENERIC_WRITE, + OPEN_EXISTING, + }, +}; diff --git a/vendor/io-lifetimes/src/impls_async_std.rs b/vendor/io-lifetimes/src/impls_async_std.rs new file mode 100644 index 000000000..534700486 --- /dev/null +++ b/vendor/io-lifetimes/src/impls_async_std.rs @@ -0,0 +1,525 @@ +//! Implementations of io-lifetimes' traits for async-std's types. In the +//! future, we'll prefer to have crates provide their own impls; this is +//! just a temporary measure. + +use crate::views::{FilelikeViewType, SocketlikeViewType}; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use crate::{ + AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, FromHandle, FromSocket, IntoHandle, + IntoSocket, OwnedHandle, OwnedSocket, +}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{ + AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket, +}; + +unsafe impl FilelikeViewType for async_std::fs::File {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::fs::File { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for async_std::fs::File { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for async_std::fs::File { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<async_std::fs::File> for OwnedFd { + #[inline] + fn from(owned: async_std::fs::File) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for async_std::fs::File { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<async_std::fs::File> for OwnedHandle { + #[inline] + fn from(owned: async_std::fs::File) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for async_std::fs::File { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for async_std::fs::File { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for async_std::fs::File { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for async_std::fs::File { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +unsafe impl SocketlikeViewType for async_std::net::TcpStream {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::net::TcpStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for async_std::net::TcpStream { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for async_std::net::TcpStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<async_std::net::TcpStream> for OwnedFd { + #[inline] + fn from(owned: async_std::net::TcpStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for async_std::net::TcpStream { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<async_std::net::TcpStream> for OwnedSocket { + #[inline] + fn from(owned: async_std::net::TcpStream) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for async_std::net::TcpStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for async_std::net::TcpStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for async_std::net::TcpStream { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for async_std::net::TcpStream { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +unsafe impl SocketlikeViewType for async_std::net::TcpListener {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::net::TcpListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for async_std::net::TcpListener { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for async_std::net::TcpListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<async_std::net::TcpListener> for OwnedFd { + #[inline] + fn from(owned: async_std::net::TcpListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for async_std::net::TcpListener { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<async_std::net::TcpListener> for OwnedSocket { + #[inline] + fn from(owned: async_std::net::TcpListener) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for async_std::net::TcpListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for async_std::net::TcpListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for async_std::net::TcpListener { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for async_std::net::TcpListener { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +unsafe impl SocketlikeViewType for async_std::net::UdpSocket {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::net::UdpSocket { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for async_std::net::UdpSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for async_std::net::UdpSocket { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<async_std::net::UdpSocket> for OwnedFd { + #[inline] + fn from(owned: async_std::net::UdpSocket) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for async_std::net::UdpSocket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<async_std::net::UdpSocket> for OwnedSocket { + #[inline] + fn from(owned: async_std::net::UdpSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for async_std::net::UdpSocket { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for async_std::net::UdpSocket { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for async_std::net::UdpSocket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for async_std::net::UdpSocket { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::io::Stdin { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for async_std::io::Stdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::io::Stdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for async_std::io::Stdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for async_std::io::Stderr { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for async_std::io::Stderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixStream {} + +#[cfg(unix)] +impl AsFd for async_std::os::unix::net::UnixStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for async_std::os::unix::net::UnixStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<async_std::os::unix::net::UnixStream> for OwnedFd { + #[inline] + fn from(owned: async_std::os::unix::net::UnixStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for async_std::os::unix::net::UnixStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for async_std::os::unix::net::UnixStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixListener {} + +#[cfg(unix)] +impl AsFd for async_std::os::unix::net::UnixListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for async_std::os::unix::net::UnixListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<async_std::os::unix::net::UnixListener> for OwnedFd { + #[inline] + fn from(owned: async_std::os::unix::net::UnixListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for async_std::os::unix::net::UnixListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for async_std::os::unix::net::UnixListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixDatagram {} + +#[cfg(unix)] +impl AsFd for async_std::os::unix::net::UnixDatagram { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for async_std::os::unix::net::UnixDatagram { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<async_std::os::unix::net::UnixDatagram> for OwnedFd { + #[inline] + fn from(owned: async_std::os::unix::net::UnixDatagram) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for async_std::os::unix::net::UnixDatagram { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for async_std::os::unix::net::UnixDatagram { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} diff --git a/vendor/io-lifetimes/src/impls_fs_err.rs b/vendor/io-lifetimes/src/impls_fs_err.rs new file mode 100644 index 000000000..6fcef362b --- /dev/null +++ b/vendor/io-lifetimes/src/impls_fs_err.rs @@ -0,0 +1,62 @@ +//! Implementations of io-lifetimes' traits for fs_err's types. In the +//! future, we'll prefer to have crates provide their own impls; this is +//! just a temporary measure. + +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use crate::{AsHandle, BorrowedHandle, IntoHandle, OwnedHandle}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle}; + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for fs_err::File { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for fs_err::File { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for fs_err::File { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<fs_err::File> for OwnedFd { + #[inline] + fn from(owned: fs_err::File) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for fs_err::File { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<fs_err::File> for OwnedHandle { + #[inline] + fn from(owned: fs_err::File) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} diff --git a/vendor/io-lifetimes/src/impls_mio.rs b/vendor/io-lifetimes/src/impls_mio.rs new file mode 100644 index 000000000..246f3b93f --- /dev/null +++ b/vendor/io-lifetimes/src/impls_mio.rs @@ -0,0 +1,478 @@ +//! Implementations of io-lifetimes' traits for mio's types. In the +//! future, we'll prefer to have crates provide their own impls; this is +//! just a temporary measure. + +#[cfg(unix)] +use crate::views::FilelikeViewType; +use crate::views::SocketlikeViewType; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use crate::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket}; + +unsafe impl SocketlikeViewType for mio::net::TcpStream {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for mio::net::TcpStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for mio::net::TcpStream { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for mio::net::TcpStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<mio::net::TcpStream> for OwnedFd { + #[inline] + fn from(owned: mio::net::TcpStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for mio::net::TcpStream { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<mio::net::TcpStream> for OwnedSocket { + #[inline] + fn from(owned: mio::net::TcpStream) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for mio::net::TcpStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for mio::net::TcpStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for mio::net::TcpStream { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for mio::net::TcpStream { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +unsafe impl SocketlikeViewType for mio::net::TcpListener {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for mio::net::TcpListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for mio::net::TcpListener { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for mio::net::TcpListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<mio::net::TcpListener> for OwnedFd { + #[inline] + fn from(owned: mio::net::TcpListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for mio::net::TcpListener { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<mio::net::TcpListener> for OwnedSocket { + #[inline] + fn from(owned: mio::net::TcpListener) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for mio::net::TcpListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for mio::net::TcpListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for mio::net::TcpListener { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for mio::net::TcpListener { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +unsafe impl SocketlikeViewType for mio::net::UdpSocket {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for mio::net::UdpSocket { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for mio::net::UdpSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for mio::net::UdpSocket { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<mio::net::UdpSocket> for OwnedFd { + #[inline] + fn from(owned: mio::net::UdpSocket) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for mio::net::UdpSocket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<mio::net::UdpSocket> for OwnedSocket { + #[inline] + fn from(owned: mio::net::UdpSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for mio::net::UdpSocket { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for mio::net::UdpSocket { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for mio::net::UdpSocket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for mio::net::UdpSocket { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for mio::net::UnixDatagram {} + +#[cfg(unix)] +impl AsFd for mio::net::UnixDatagram { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for mio::net::UnixDatagram { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<mio::net::UnixDatagram> for OwnedFd { + #[inline] + fn from(owned: mio::net::UnixDatagram) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for mio::net::UnixDatagram { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for mio::net::UnixDatagram { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for mio::net::UnixListener {} + +#[cfg(unix)] +impl AsFd for mio::net::UnixListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for mio::net::UnixListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<mio::net::UnixListener> for OwnedFd { + #[inline] + fn from(owned: mio::net::UnixListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for mio::net::UnixListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for mio::net::UnixListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for mio::net::UnixStream {} + +#[cfg(unix)] +impl AsFd for mio::net::UnixStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for mio::net::UnixStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<mio::net::UnixStream> for OwnedFd { + #[inline] + fn from(owned: mio::net::UnixStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for mio::net::UnixStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for mio::net::UnixStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +unsafe impl FilelikeViewType for mio::unix::pipe::Receiver {} + +#[cfg(unix)] +impl AsFd for mio::unix::pipe::Receiver { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for mio::unix::pipe::Receiver { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<mio::unix::pipe::Receiver> for OwnedFd { + #[inline] + fn from(owned: mio::unix::pipe::Receiver) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for mio::unix::pipe::Receiver { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for mio::unix::pipe::Receiver { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +unsafe impl FilelikeViewType for mio::unix::pipe::Sender {} + +#[cfg(unix)] +impl AsFd for mio::unix::pipe::Sender { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for mio::unix::pipe::Sender { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<mio::unix::pipe::Sender> for OwnedFd { + #[inline] + fn from(owned: mio::unix::pipe::Sender) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for mio::unix::pipe::Sender { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for mio::unix::pipe::Sender { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} diff --git a/vendor/io-lifetimes/src/impls_os_pipe.rs b/vendor/io-lifetimes/src/impls_os_pipe.rs new file mode 100644 index 000000000..e0544873e --- /dev/null +++ b/vendor/io-lifetimes/src/impls_os_pipe.rs @@ -0,0 +1,179 @@ +//! Implementations of io-lifetimes' traits for os_pipe's types. In the +//! future, we'll prefer to have crates provide their own impls; this is +//! just a temporary measure. + +use crate::views::FilelikeViewType; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use crate::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle}; + +unsafe impl FilelikeViewType for os_pipe::PipeReader {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for os_pipe::PipeReader { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for os_pipe::PipeReader { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for os_pipe::PipeReader { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<os_pipe::PipeReader> for OwnedFd { + #[inline] + fn from(owned: os_pipe::PipeReader) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for os_pipe::PipeReader { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<os_pipe::PipeReader> for OwnedHandle { + #[inline] + fn from(owned: os_pipe::PipeReader) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for os_pipe::PipeReader { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for os_pipe::PipeReader { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for os_pipe::PipeReader { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for os_pipe::PipeReader { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +unsafe impl FilelikeViewType for os_pipe::PipeWriter {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for os_pipe::PipeWriter { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for os_pipe::PipeWriter { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for os_pipe::PipeWriter { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<os_pipe::PipeWriter> for OwnedFd { + #[inline] + fn from(owned: os_pipe::PipeWriter) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for os_pipe::PipeWriter { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<os_pipe::PipeWriter> for OwnedHandle { + #[inline] + fn from(owned: os_pipe::PipeWriter) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for os_pipe::PipeWriter { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for os_pipe::PipeWriter { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for os_pipe::PipeWriter { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for os_pipe::PipeWriter { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} diff --git a/vendor/io-lifetimes/src/impls_socket2.rs b/vendor/io-lifetimes/src/impls_socket2.rs new file mode 100644 index 000000000..fbfeb67d7 --- /dev/null +++ b/vendor/io-lifetimes/src/impls_socket2.rs @@ -0,0 +1,97 @@ +//! Implementations of io-lifetimes' traits for socket2's types. In the +//! future, we'll prefer to have crates provide their own impls; this is +//! just a temporary measure. + +use crate::views::SocketlikeViewType; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use crate::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket}; + +unsafe impl SocketlikeViewType for socket2::Socket {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for socket2::Socket { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for socket2::Socket { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for socket2::Socket { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<socket2::Socket> for OwnedFd { + #[inline] + fn from(owned: socket2::Socket) -> Self { + unsafe { OwnedFd::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for socket2::Socket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<socket2::Socket> for OwnedSocket { + #[inline] + fn from(owned: socket2::Socket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for socket2::Socket { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for socket2::Socket { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for socket2::Socket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for socket2::Socket { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} diff --git a/vendor/io-lifetimes/src/impls_std.rs b/vendor/io-lifetimes/src/impls_std.rs new file mode 100644 index 000000000..27275fa68 --- /dev/null +++ b/vendor/io-lifetimes/src/impls_std.rs @@ -0,0 +1,888 @@ +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, FromFd, IntoFd}; +#[cfg(windows)] +use crate::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSocket}; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{BorrowedFd, OwnedFd}; +#[cfg(windows)] +use crate::{BorrowedHandle, BorrowedSocket, HandleOrInvalid, OwnedHandle, OwnedSocket}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{ + AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket, +}; + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for BorrowedFd<'_> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for BorrowedHandle<'_> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsSocket for BorrowedSocket<'_> { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for OwnedFd { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for OwnedHandle { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsSocket for OwnedSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for OwnedFd { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { Self::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for OwnedHandle { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { Self::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl IntoSocket for OwnedSocket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { Self::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for OwnedFd { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for OwnedHandle { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl FromSocket for OwnedSocket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl FromHandle for HandleOrInvalid { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for HandleOrInvalid { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::fs::File { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::fs::File { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::fs::File { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<std::fs::File> for OwnedFd { + #[inline] + fn from(owned: std::fs::File) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::fs::File { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<std::fs::File> for OwnedHandle { + #[inline] + fn from(owned: std::fs::File) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::fs::File { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for std::fs::File { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for std::fs::File { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for std::fs::File { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::net::TcpStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for std::net::TcpStream { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::net::TcpStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<std::net::TcpStream> for OwnedFd { + #[inline] + fn from(owned: std::net::TcpStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for std::net::TcpStream { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<std::net::TcpStream> for OwnedSocket { + #[inline] + fn from(owned: std::net::TcpStream) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::net::TcpStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for std::net::TcpStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for std::net::TcpStream { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for std::net::TcpStream { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::net::TcpListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for std::net::TcpListener { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::net::TcpListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<std::net::TcpListener> for OwnedFd { + #[inline] + fn from(owned: std::net::TcpListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for std::net::TcpListener { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<std::net::TcpListener> for OwnedSocket { + #[inline] + fn from(owned: std::net::TcpListener) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::net::TcpListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for std::net::TcpListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for std::net::TcpListener { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for std::net::TcpListener { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::net::UdpSocket { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for std::net::UdpSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::net::UdpSocket { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<std::net::UdpSocket> for OwnedFd { + #[inline] + fn from(owned: std::net::UdpSocket) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for std::net::UdpSocket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<std::net::UdpSocket> for OwnedSocket { + #[inline] + fn from(owned: std::net::UdpSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::net::UdpSocket { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for std::net::UdpSocket { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for std::net::UdpSocket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From<OwnedSocket> for std::net::UdpSocket { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::io::Stdin { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::io::Stdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<'a> AsFd for std::io::StdinLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl<'a> AsHandle for std::io::StdinLock<'a> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::io::Stdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::io::Stdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<'a> AsFd for std::io::StdoutLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl<'a> AsHandle for std::io::StdoutLock<'a> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::io::Stderr { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::io::Stderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<'a> AsFd for std::io::StderrLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl<'a> AsHandle for std::io::StderrLock<'a> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::process::ChildStdin { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::ChildStdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::process::ChildStdin { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<std::process::ChildStdin> for OwnedFd { + #[inline] + fn from(owned: std::process::ChildStdin) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::ChildStdin { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<std::process::ChildStdin> for OwnedHandle { + #[inline] + fn from(owned: std::process::ChildStdin) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::process::ChildStdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::ChildStdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::process::ChildStdout { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<std::process::ChildStdout> for OwnedFd { + #[inline] + fn from(owned: std::process::ChildStdout) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::ChildStdout { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<std::process::ChildStdout> for OwnedHandle { + #[inline] + fn from(owned: std::process::ChildStdout) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::process::ChildStderr { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::ChildStderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::process::ChildStderr { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<std::process::ChildStderr> for OwnedFd { + #[inline] + fn from(owned: std::process::ChildStderr) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::ChildStderr { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<std::process::ChildStderr> for OwnedHandle { + #[inline] + fn from(owned: std::process::ChildStderr) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl FromFd for std::process::Stdio { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for std::process::Stdio { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for std::process::Stdio { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for std::process::Stdio { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::Child { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::Child { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<std::process::Child> for OwnedHandle { + #[inline] + fn from(owned: std::process::Child) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::os::unix::net::UnixStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::os::unix::net::UnixStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<std::os::unix::net::UnixStream> for OwnedFd { + #[inline] + fn from(owned: std::os::unix::net::UnixStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for std::os::unix::net::UnixStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for std::os::unix::net::UnixStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl AsFd for std::os::unix::net::UnixListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::os::unix::net::UnixListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<std::os::unix::net::UnixListener> for OwnedFd { + #[inline] + fn from(owned: std::os::unix::net::UnixListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for std::os::unix::net::UnixListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for std::os::unix::net::UnixListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl AsFd for std::os::unix::net::UnixDatagram { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::os::unix::net::UnixDatagram { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<std::os::unix::net::UnixDatagram> for OwnedFd { + #[inline] + fn from(owned: std::os::unix::net::UnixDatagram) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for std::os::unix::net::UnixDatagram { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From<OwnedFd> for std::os::unix::net::UnixDatagram { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl<T> AsHandle for std::thread::JoinHandle<T> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl<T> IntoHandle for std::thread::JoinHandle<T> { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl<T> From<std::thread::JoinHandle<T>> for OwnedHandle { + #[inline] + fn from(owned: std::thread::JoinHandle<T>) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} diff --git a/vendor/io-lifetimes/src/impls_std_views.rs b/vendor/io-lifetimes/src/impls_std_views.rs new file mode 100644 index 000000000..ffa013ffa --- /dev/null +++ b/vendor/io-lifetimes/src/impls_std_views.rs @@ -0,0 +1,31 @@ +use crate::views::{FilelikeViewType, SocketlikeViewType}; +#[cfg(any(unix, target_os = "wasi"))] +use crate::OwnedFd; +#[cfg(windows)] +use crate::{OwnedHandle, OwnedSocket}; + +#[cfg(any(unix, target_os = "wasi"))] +unsafe impl FilelikeViewType for OwnedFd {} + +#[cfg(windows)] +unsafe impl FilelikeViewType for OwnedHandle {} + +#[cfg(windows)] +unsafe impl SocketlikeViewType for OwnedSocket {} + +unsafe impl FilelikeViewType for std::fs::File {} + +unsafe impl SocketlikeViewType for std::net::TcpStream {} + +unsafe impl SocketlikeViewType for std::net::TcpListener {} + +unsafe impl SocketlikeViewType for std::net::UdpSocket {} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for std::os::unix::net::UnixStream {} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for std::os::unix::net::UnixListener {} + +#[cfg(unix)] +unsafe impl SocketlikeViewType for std::os::unix::net::UnixDatagram {} diff --git a/vendor/io-lifetimes/src/impls_tokio.rs b/vendor/io-lifetimes/src/impls_tokio.rs new file mode 100644 index 000000000..6dfde9136 --- /dev/null +++ b/vendor/io-lifetimes/src/impls_tokio.rs @@ -0,0 +1,214 @@ +//! Implementations of io-lifetimes' traits for tokio's types. In the +//! future, we'll prefer to have crates provide their own impls; this is +//! just a temporary measure. + +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, FromFd, OwnedFd}; +#[cfg(windows)] +use crate::{AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, FromHandle, OwnedHandle}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{AsRawHandle, AsRawSocket, FromRawHandle, IntoRawHandle}; + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::fs::File { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::fs::File { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for tokio::fs::File { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From<OwnedFd> for tokio::fs::File { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for tokio::fs::File { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From<OwnedHandle> for tokio::fs::File { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::net::TcpStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for tokio::net::TcpStream { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::net::TcpListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for tokio::net::TcpListener { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::net::UdpSocket { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for tokio::net::UdpSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::io::Stdin { + #[inline] + fn as_fd(&self) -> BorrowedFd { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::io::Stdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::io::Stdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::io::Stdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::io::Stderr { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::io::Stderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for tokio::net::UnixStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl AsFd for tokio::net::UnixListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl AsFd for tokio::net::UnixDatagram { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for tokio::process::ChildStdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::process::ChildStdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::process::ChildStdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsHandle for tokio::process::ChildStderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} diff --git a/vendor/io-lifetimes/src/lib.rs b/vendor/io-lifetimes/src/lib.rs new file mode 100644 index 000000000..5e2a9d19f --- /dev/null +++ b/vendor/io-lifetimes/src/lib.rs @@ -0,0 +1,179 @@ +//! Experimental new types and traits to replace the `Raw` family of types and +//! traits. +//! +//! This API has much conceptual similarity with the `Raw` API, but introduces +//! explicit concepts of ownership and borrowing: +//! +//! | `Raw` API | This experimental API | +//! | ---------- | ------------------------ | +//! | `Raw*` | `Borrowed*` and `Owned*` | +//! | `AsRaw*` | `As*` | +//! | `IntoRaw*` | `Into*` | +//! | `FromRaw*` | `From*` | +//! +//! This gives it several advantages: +//! +//! - Less `unsafe` in user code! +//! +//! - Easier to understand ownership. +//! +//! - It avoids the inconsistency where `AsRawFd` and `IntoRawFd` return +//! `RawFd` values that users ought to be able to trust, but aren't unsafe, +//! so it's possible to fail to uphold this trust in purely safe Rust. +//! +//! - It enables a number of safe and portable convenience features, such as +//! [safe typed views] and [from+into conversions]. +//! +//! [safe typed views]: AsFilelike::as_filelike_view +//! [from+into conversions]: FromFilelike::from_into_filelike + +#![deny(missing_docs)] +#![cfg_attr(rustc_attrs, feature(rustc_attrs))] +#![cfg_attr(all(io_lifetimes_use_std, target_os = "wasi"), feature(wasi_ext))] +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +mod portability; +mod traits; +#[cfg(not(io_lifetimes_use_std))] +mod types; + +#[cfg(not(io_lifetimes_use_std))] +mod impls_std; +mod impls_std_views; + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(any(unix, target_os = "wasi"))] +pub use traits::AsFd; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +pub use traits::{AsHandle, AsSocket}; +#[cfg(any(unix, target_os = "wasi"))] +pub use traits::{FromFd, IntoFd}; +#[cfg(windows)] +pub use traits::{FromHandle, FromSocket, IntoHandle, IntoSocket}; + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(any(unix, target_os = "wasi"))] +pub use types::{BorrowedFd, OwnedFd}; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +pub use types::{ + BorrowedHandle, BorrowedSocket, HandleOrInvalid, InvalidHandleError, NullHandleError, + OwnedHandle, OwnedSocket, +}; + +#[cfg(io_lifetimes_use_std)] +#[cfg(unix)] +pub use std::os::unix::io::{AsFd, BorrowedFd, OwnedFd}; +#[cfg(io_lifetimes_use_std)] +#[cfg(target_os = "wasi")] +pub use std::os::wasi::io::{AsFd, BorrowedFd, OwnedFd}; +#[cfg(io_lifetimes_use_std)] +#[cfg(windows)] +pub use std::os::windows::io::{ + AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, HandleOrInvalid, InvalidHandleError, + NullHandleError, OwnedHandle, OwnedSocket, +}; + +// io-lifetimes defined `FromFd`/`IntoFd` traits instead of just using +// `From`/`Into` because that allowed it to implement them for foreign types, +// including std types like File and TcpStream, and popular third-party types. +// +// std just uses `From`/`Into`, because it defines those traits itself so it +// can implement them for std types itself, and std won't be implementing them +// for third-party types. However, this means that until `OwnedFd` et al are +// stabilized, there will be no impls for third-party traits. +// +// So we define `FromFd`/`IntoFd` traits, and implement them in terms of +// `From`/`Into`, +#[cfg(io_lifetimes_use_std)] +#[cfg(any(unix, target_os = "wasi"))] +impl<T: From<OwnedFd>> FromFd for T { + #[inline] + fn from_fd(owned_fd: OwnedFd) -> Self { + owned_fd.into() + } +} +#[cfg(io_lifetimes_use_std)] +#[cfg(any(unix, target_os = "wasi"))] +impl<T> IntoFd for T +where + OwnedFd: From<T>, +{ + #[inline] + fn into_fd(self) -> OwnedFd { + self.into() + } +} + +#[cfg(io_lifetimes_use_std)] +#[cfg(windows)] +impl<T: From<OwnedHandle>> FromHandle for T { + #[inline] + fn from_handle(owned_handle: OwnedHandle) -> Self { + owned_handle.into() + } +} +#[cfg(io_lifetimes_use_std)] +#[cfg(windows)] +impl<T> IntoHandle for T +where + OwnedHandle: From<T>, +{ + #[inline] + fn into_handle(self) -> OwnedHandle { + self.into() + } +} + +#[cfg(io_lifetimes_use_std)] +#[cfg(windows)] +impl<T: From<OwnedSocket>> FromSocket for T { + #[inline] + fn from_socket(owned_socket: OwnedSocket) -> Self { + owned_socket.into() + } +} +#[cfg(io_lifetimes_use_std)] +#[cfg(windows)] +impl<T> IntoSocket for T +where + OwnedSocket: From<T>, +{ + #[inline] + fn into_socket(self) -> OwnedSocket { + self.into() + } +} + +pub use portability::{ + AsFilelike, AsSocketlike, BorrowedFilelike, BorrowedSocketlike, FromFilelike, FromSocketlike, + IntoFilelike, IntoSocketlike, OwnedFilelike, OwnedSocketlike, +}; + +#[cfg(feature = "close")] +pub mod example_ffi; +pub mod raw; +pub mod views; + +// Ideally, we'd want crates to implement our traits themselves. But for now, +// while we're prototyping, we provide a few impls on foreign types. +#[cfg(not(io_lifetimes_use_std))] +#[cfg(feature = "async-std")] +mod impls_async_std; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(feature = "fs-err")] +mod impls_fs_err; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(feature = "mio")] +mod impls_mio; +#[cfg(not(target_os = "wasi"))] +#[cfg(not(io_lifetimes_use_std))] +#[cfg(feature = "os_pipe")] +mod impls_os_pipe; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(feature = "socket2")] +mod impls_socket2; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(feature = "tokio")] +mod impls_tokio; diff --git a/vendor/io-lifetimes/src/portability.rs b/vendor/io-lifetimes/src/portability.rs new file mode 100644 index 000000000..ee9057501 --- /dev/null +++ b/vendor/io-lifetimes/src/portability.rs @@ -0,0 +1,518 @@ +//! Portability abstractions over `Owned*` and `Borrowed*`. +//! +//! On Unix, "everything is a file descriptor". On Windows, file/pipe/process +//! handles are distinct from socket descriptors. This file provides a minimal +//! layer of portability over this difference. + +use crate::views::{FilelikeView, FilelikeViewType, SocketlikeView, SocketlikeViewType}; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +#[cfg(windows)] +use crate::{ + AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, FromHandle, FromSocket, IntoHandle, + IntoSocket, OwnedHandle, OwnedSocket, +}; + +/// A reference to a filelike object. +/// +/// This is a portability abstraction over Unix-like [`BorrowedFd`] and +/// Windows' `BorrowedHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub type BorrowedFilelike<'filelike> = BorrowedFd<'filelike>; + +/// A reference to a filelike object. +/// +/// This is a portability abstraction over Unix-like `BorrowedFd` and +/// Windows' [`BorrowedHandle`]. +#[cfg(windows)] +pub type BorrowedFilelike<'filelike> = BorrowedHandle<'filelike>; + +/// A reference to a socketlike object. +/// +/// This is a portability abstraction over Unix-like [`BorrowedFd`] and +/// Windows' `BorrowedSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub type BorrowedSocketlike<'socketlike> = BorrowedFd<'socketlike>; + +/// A reference to a socketlike object. +/// +/// This is a portability abstraction over Unix-like `BorrowedFd` and +/// Windows' [`BorrowedSocket`]. +#[cfg(windows)] +pub type BorrowedSocketlike<'socketlike> = BorrowedSocket<'socketlike>; + +/// An owned filelike object. +/// +/// This is a portability abstraction over Unix-like [`OwnedFd`] and +/// Windows' `OwnedHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub type OwnedFilelike = OwnedFd; + +/// An owned filelike object. +/// +/// This is a portability abstraction over Unix-like `OwnedFd` and +/// Windows' [`OwnedHandle`]. +#[cfg(windows)] +pub type OwnedFilelike = OwnedHandle; + +/// An owned socketlike object. +/// +/// This is a portability abstraction over Unix-like [`OwnedFd`] and +/// Windows' `OwnedSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub type OwnedSocketlike = OwnedFd; + +/// An owned socketlike object. +/// +/// This is a portability abstraction over Unix-like `OwnedFd` and +/// Windows' [`OwnedSocket`]. +#[cfg(windows)] +pub type OwnedSocketlike = OwnedSocket; + +/// A portable trait to borrow a reference from an underlying filelike object. +/// +/// This is a portability abstraction over Unix-like [`AsFd`] and Windows' +/// `AsHandle`. It also provides the `as_filelike_view` convenience function +/// providing typed views. +#[cfg(any(unix, target_os = "wasi"))] +pub trait AsFilelike: AsFd { + /// Borrows the reference. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{AsFilelike, BorrowedFilelike}; + /// + /// let mut f = File::open("foo.txt")?; + /// let borrowed_filelike: BorrowedFilelike<'_> = f.as_filelike(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn as_filelike(&self) -> BorrowedFilelike<'_>; + + /// Return a borrowing view of a resource which dereferences to a `&Target`. + /// + /// Note that [`Read`] or [`Write`] require `&mut Target`, but in some cases, + /// such as [`File`], `Read` and `Write` are implemented for `&Target` in + /// addition to `Target`, and you can get a `&mut &Target` by doing `&*` on + /// the resuting view, like this: + /// + /// ```rust,ignore + /// let v = f.as_filelike_view::<std::fs::File>(); + /// (&*v).read(&mut buf).unwrap(); + /// ``` + /// + /// [`File`]: std::fs::File + fn as_filelike_view<Target: FilelikeViewType>(&self) -> FilelikeView<'_, Target>; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: AsFd> AsFilelike for T { + #[inline] + fn as_filelike(&self) -> BorrowedFilelike<'_> { + self.as_fd() + } + + #[inline] + fn as_filelike_view<Target: FilelikeViewType>(&self) -> FilelikeView<'_, Target> { + FilelikeView::new(self) + } +} + +/// A portable trait to borrow a reference from an underlying filelike object. +/// +/// This is a portability abstraction over Unix-like `AsFd` and Windows' +/// [`AsHandle`]. It also provides the `as_filelike_view` convenience function +/// providing typed views. +#[cfg(windows)] +pub trait AsFilelike: AsHandle { + /// Borrows the reference. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{AsFilelike, BorrowedFilelike}; + /// + /// let mut f = File::open("foo.txt")?; + /// let borrowed_filelike: BorrowedFilelike<'_> = f.as_filelike(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn as_filelike(&self) -> BorrowedFilelike<'_>; + + /// Return a borrowing view of a resource which dereferences to a `&Target`. + /// + /// Note that [`Read`] or [`Write`] require `&mut Target`, but in some cases, + /// such as [`File`], `Read` and `Write` are implemented for `&Target` in + /// addition to `Target`, and you can get a `&mut &Target` by doing `&*` on + /// the resuting view, like this: + /// + /// ```rust,ignore + /// let v = f.as_filelike_view::<std::fs::File>(); + /// (&*v).read(&mut buf).unwrap(); + /// ``` + /// + /// [`File`]: std::fs::File + fn as_filelike_view<Target: FilelikeViewType>(&self) -> FilelikeView<'_, Target>; +} + +#[cfg(windows)] +impl<T: AsHandle> AsFilelike for T { + #[inline] + fn as_filelike(&self) -> BorrowedFilelike<'_> { + self.as_handle() + } + + #[inline] + fn as_filelike_view<Target: FilelikeViewType>(&self) -> FilelikeView<'_, Target> { + FilelikeView::new(self) + } +} + +/// A portable trait to borrow a reference from an underlying socketlike +/// object. +/// +/// This is a portability abstraction over Unix-like [`AsFd`] and Windows' +/// `AsSocket`. It also provides the `as_socketlike_view` convenience +/// function providing typed views. +#[cfg(any(unix, target_os = "wasi"))] +pub trait AsSocketlike: AsFd { + /// Borrows the reference. + fn as_socketlike(&self) -> BorrowedSocketlike<'_>; + + /// Return a borrowing view of a resource which dereferences to a `&Target`. + /// + /// Note that [`Read`] or [`Write`] require `&mut Target`, but in some cases, + /// such as [`TcpStream`], `Read` and `Write` are implemented for `&Target` in + /// addition to `Target`, and you can get a `&mut &Target` by doing `&*` on + /// the resuting view, like this: + /// + /// ```rust,ignore + /// let v = s.as_socketlike_view::<std::net::TcpStream>(); + /// (&*v).read(&mut buf).unwrap(); + /// ``` + /// + /// [`TcpStream`]: std::net::TcpStream + fn as_socketlike_view<Target: SocketlikeViewType>(&self) -> SocketlikeView<'_, Target>; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: AsFd> AsSocketlike for T { + #[inline] + fn as_socketlike(&self) -> BorrowedSocketlike<'_> { + self.as_fd() + } + + #[inline] + fn as_socketlike_view<Target: SocketlikeViewType>(&self) -> SocketlikeView<'_, Target> { + SocketlikeView::new(self) + } +} + +/// A portable trait to borrow a reference from an underlying socketlike +/// object. +/// +/// This is a portability abstraction over Unix-like `AsFd` and Windows' +/// [`AsSocket`]. It also provides the `as_socketlike_view` convenience +/// function providing typed views. +#[cfg(windows)] +pub trait AsSocketlike: AsSocket { + /// Borrows the reference. + fn as_socketlike(&self) -> BorrowedSocketlike; + + /// Return a borrowing view of a resource which dereferences to a `&Target`. + /// + /// Note that [`Read`] or [`Write`] require `&mut Target`, but in some cases, + /// such as [`TcpStream`], `Read` and `Write` are implemented for `&Target` in + /// addition to `Target`, and you can get a `&mut &Target` by doing `&*` on + /// the resuting view, like this: + /// + /// ```rust,ignore + /// let v = s.as_socketlike_view::<std::net::TcpStream>(); + /// (&*v).read(&mut buf).unwrap(); + /// ``` + /// + /// [`TcpStream`]: std::net::TcpStream + fn as_socketlike_view<Target: SocketlikeViewType>(&self) -> SocketlikeView<'_, Target>; +} + +#[cfg(windows)] +impl<T: AsSocket> AsSocketlike for T { + #[inline] + fn as_socketlike(&self) -> BorrowedSocketlike<'_> { + self.as_socket() + } + + #[inline] + fn as_socketlike_view<Target: SocketlikeViewType>(&self) -> SocketlikeView<'_, Target> { + SocketlikeView::new(self) + } +} + +/// A portable trait to express the ability to consume an object and acquire +/// ownership of its filelike object. +/// +/// This is a portability abstraction over Unix-like [`IntoFd`] and Windows' +/// `IntoHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait IntoFilelike: IntoFd { + /// Consumes this object, returning the underlying filelike object. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{IntoFilelike, OwnedFilelike}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_filelike: OwnedFilelike = f.into_filelike(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn into_filelike(self) -> OwnedFilelike; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: IntoFd> IntoFilelike for T { + #[inline] + fn into_filelike(self) -> OwnedFilelike { + self.into_fd() + } +} + +/// A portable trait to express the ability to consume an object and acquire +/// ownership of its filelike object. +/// +/// This is a portability abstraction over Unix-like `IntoFd` and Windows' +/// [`IntoHandle`]. +#[cfg(windows)] +pub trait IntoFilelike: IntoHandle { + /// Consumes this object, returning the underlying filelike object. + fn into_filelike(self) -> OwnedFilelike; +} + +#[cfg(windows)] +impl<T: IntoHandle> IntoFilelike for T { + #[inline] + fn into_filelike(self) -> OwnedFilelike { + self.into_handle() + } +} + +/// A portable trait to express the ability to consume an object and acquire +/// ownership of its socketlike object. +/// +/// This is a portability abstraction over Unix-like [`IntoFd`] and Windows' +/// `IntoSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait IntoSocketlike: IntoFd { + /// Consumes this object, returning the underlying socketlike object. + fn into_socketlike(self) -> OwnedSocketlike; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: IntoFd> IntoSocketlike for T { + #[inline] + fn into_socketlike(self) -> OwnedSocketlike { + self.into_fd() + } +} + +/// A portable trait to express the ability to consume an object and acquire +/// ownership of its socketlike object. +/// +/// This is a portability abstraction over Unix-like `IntoFd` and Windows' +/// [`IntoSocket`]. +#[cfg(windows)] +pub trait IntoSocketlike: IntoSocket { + /// Consumes this object, returning the underlying socketlike object. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{IntoFilelike, OwnedFilelike}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_filelike: OwnedFilelike = f.into_filelike(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn into_socketlike(self) -> OwnedSocketlike; +} + +#[cfg(windows)] +impl<T: IntoSocket> IntoSocketlike for T { + #[inline] + fn into_socketlike(self) -> OwnedSocketlike { + self.into_socket() + } +} + +/// A portable trait to express the ability to construct an object from a +/// filelike object. +/// +/// This is a portability abstraction over Unix-like [`FromFd`] and Windows' +/// `FromHandle`. It also provides the `from_into_filelike` convenience +/// function providing simplified from+into conversions. +#[cfg(any(unix, target_os = "wasi"))] +pub trait FromFilelike: FromFd { + /// Constructs a new instance of `Self` from the given filelike object. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromFilelike, IntoFilelike, OwnedFilelike}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_filelike: OwnedFilelike = f.into_filelike(); + /// let f = File::from_filelike(owned_filelike); + /// # Ok::<(), io::Error>(()) + /// ``` + fn from_filelike(owned: OwnedFilelike) -> Self; + + /// Constructs a new instance of `Self` from the given filelike object + /// converted from `into_owned`. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromFilelike, IntoFilelike}; + /// + /// let f = File::open("foo.txt")?; + /// let f = File::from_into_filelike(f); + /// # Ok::<(), io::Error>(()) + /// ``` + fn from_into_filelike<Owned: IntoFilelike>(owned: Owned) -> Self; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: FromFd> FromFilelike for T { + #[inline] + fn from_filelike(owned: OwnedFilelike) -> Self { + Self::from_fd(owned) + } + + #[inline] + fn from_into_filelike<Owned: IntoFilelike>(owned: Owned) -> Self { + Self::from_filelike(owned.into_filelike()) + } +} + +/// A portable trait to express the ability to construct an object from a +/// filelike object. +/// +/// This is a portability abstraction over Unix-like `FromFd` and Windows' +/// [`FromHandle`]. It also provides the `from_into_filelike` convenience +/// function providing simplified from+into conversions. +#[cfg(windows)] +pub trait FromFilelike: FromHandle { + /// Constructs a new instance of `Self` from the given filelike object. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromFilelike, IntoFilelike, OwnedFilelike}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_filelike: OwnedFilelike = f.into_filelike(); + /// let f = File::from_filelike(owned_filelike); + /// # Ok::<(), io::Error>(()) + /// ``` + fn from_filelike(owned: OwnedFilelike) -> Self; + + /// Constructs a new instance of `Self` from the given filelike object + /// converted from `into_owned`. + /// + /// # Example + /// + /// ```rust,no_run + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromFilelike, IntoFilelike}; + /// + /// let f = File::open("foo.txt")?; + /// let f = File::from_into_filelike(f); + /// # Ok::<(), io::Error>(()) + /// ``` + fn from_into_filelike<Owned: IntoFilelike>(owned: Owned) -> Self; +} + +#[cfg(windows)] +impl<T: FromHandle> FromFilelike for T { + #[inline] + fn from_filelike(owned: OwnedFilelike) -> Self { + Self::from_handle(owned) + } + + #[inline] + fn from_into_filelike<Owned: IntoFilelike>(owned: Owned) -> Self { + Self::from_filelike(owned.into_filelike()) + } +} + +/// A portable trait to express the ability to construct an object from a +/// socketlike object. +/// +/// This is a portability abstraction over Unix-like [`FromFd`] and Windows' +/// `FromSocket`. It also provides the `from_into_socketlike` convenience +/// function providing simplified from+into conversions. +#[cfg(any(unix, target_os = "wasi"))] +pub trait FromSocketlike: FromFd { + /// Constructs a new instance of `Self` from the given socketlike object. + fn from_socketlike(owned: OwnedSocketlike) -> Self; + + /// Constructs a new instance of `Self` from the given socketlike object + /// converted from `into_owned`. + fn from_into_socketlike<Owned: IntoSocketlike>(owned: Owned) -> Self; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: FromFd> FromSocketlike for T { + #[inline] + fn from_socketlike(owned: OwnedSocketlike) -> Self { + Self::from_fd(owned) + } + + #[inline] + fn from_into_socketlike<Owned: IntoSocketlike>(owned: Owned) -> Self { + Self::from_socketlike(owned.into_socketlike()) + } +} + +/// A portable trait to express the ability to construct an object from a +/// socketlike object. +/// +/// This is a portability abstraction over Unix-like `FromFd` and Windows' +/// [`FromSocket`]. It also provides the `from_into_socketlike` convenience +/// function providing simplified from+into conversions. +#[cfg(windows)] +pub trait FromSocketlike: FromSocket { + /// Constructs a new instance of `Self` from the given socketlike object. + fn from_socketlike(owned: OwnedSocketlike) -> Self; + + /// Constructs a new instance of `Self` from the given socketlike object + /// converted from `into_owned`. + fn from_into_socketlike<Owned: IntoSocketlike>(owned: Owned) -> Self; +} + +#[cfg(windows)] +impl<T: FromSocket> FromSocketlike for T { + #[inline] + fn from_socketlike(owned: OwnedSocketlike) -> Self { + Self::from_socket(owned) + } + + #[inline] + fn from_into_socketlike<Owned: IntoSocketlike>(owned: Owned) -> Self { + Self::from_socketlike(owned.into_socketlike()) + } +} diff --git a/vendor/io-lifetimes/src/raw.rs b/vendor/io-lifetimes/src/raw.rs new file mode 100644 index 000000000..0264f4084 --- /dev/null +++ b/vendor/io-lifetimes/src/raw.rs @@ -0,0 +1,253 @@ +//! Portability abstractions over `Raw*`. +//! +//! On Unix, "everything is a file descriptor". On Windows, file/pipe/process +//! handles are distinct from socket descriptors. This file provides a minimal +//! layer of portability over this difference. + +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +#[cfg(windows)] +use std::os::windows::io::{ + AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket, + RawHandle, RawSocket, +}; + +/// A raw filelike object. +/// +/// This is a portability abstraction over Unix-like [`RawFd`] and +/// Windows' `RawHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub type RawFilelike = RawFd; + +/// A raw filelike object. +/// +/// This is a portability abstraction over Unix-like `RawFd` and +/// Windows' [`RawHandle`]. +#[cfg(windows)] +pub type RawFilelike = RawHandle; + +/// A raw socketlike object. +/// +/// This is a portability abstraction over Unix-like [`RawFd`] and +/// Windows' `RawSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub type RawSocketlike = RawFd; + +/// A raw socketlike object. +/// +/// This is a portability abstraction over Unix-like `RawFd` and +/// Windows' [`RawSocket`]. +#[cfg(windows)] +pub type RawSocketlike = RawSocket; + +/// A portable trait to obtain the raw value of an underlying filelike object. +/// +/// This is a portability abstraction over Unix-like [`AsRawFd`] and Windows' +/// `AsRawHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait AsRawFilelike: AsRawFd { + /// Returns the raw value. + fn as_raw_filelike(&self) -> RawFilelike; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: AsRawFd> AsRawFilelike for T { + #[inline] + fn as_raw_filelike(&self) -> RawFilelike { + self.as_raw_fd() + } +} + +/// This is a portability abstraction over Unix-like `AsRawFd` and Windows' +/// [`AsRawHandle`]. +#[cfg(windows)] +pub trait AsRawFilelike: AsRawHandle { + /// Returns the raw value. + fn as_raw_filelike(&self) -> RawFilelike; +} + +#[cfg(windows)] +impl<T: AsRawHandle> AsRawFilelike for T { + #[inline] + fn as_raw_filelike(&self) -> RawFilelike { + self.as_raw_handle() + } +} + +/// This is a portability abstraction over Unix-like [`AsRawFd`] and Windows' +/// `AsRawSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait AsRawSocketlike: AsRawFd { + /// Returns the raw value. + fn as_raw_socketlike(&self) -> RawSocketlike; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: AsRawFd> AsRawSocketlike for T { + #[inline] + fn as_raw_socketlike(&self) -> RawSocketlike { + self.as_raw_fd() + } +} + +/// This is a portability abstraction over Unix-like `AsRawFd` and Windows' +/// [`AsRawSocket`]. +#[cfg(windows)] +pub trait AsRawSocketlike: AsRawSocket { + /// Returns the raw value. + fn as_raw_socketlike(&self) -> RawSocketlike; +} + +#[cfg(windows)] +impl<T: AsRawSocket> AsRawSocketlike for T { + #[inline] + fn as_raw_socketlike(&self) -> RawSocketlike { + self.as_raw_socket() + } +} + +/// This is a portability abstraction over Unix-like [`IntoRawFd`] and Windows' +/// `IntoRawHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait IntoRawFilelike: IntoRawFd { + /// Returns the raw value. + fn into_raw_filelike(self) -> RawFilelike; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: IntoRawFd> IntoRawFilelike for T { + #[inline] + fn into_raw_filelike(self) -> RawFilelike { + self.into_raw_fd() + } +} + +/// This is a portability abstraction over Unix-like `IntoRawFd` and Windows' +/// [`IntoRawHandle`]. +#[cfg(windows)] +pub trait IntoRawFilelike: IntoRawHandle { + /// Returns the raw value. + fn into_raw_filelike(self) -> RawFilelike; +} + +#[cfg(windows)] +impl<T: IntoRawHandle> IntoRawFilelike for T { + #[inline] + fn into_raw_filelike(self) -> RawFilelike { + self.into_raw_handle() + } +} + +/// This is a portability abstraction over Unix-like [`IntoRawFd`] and Windows' +/// `IntoRawSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait IntoRawSocketlike: IntoRawFd { + /// Returns the raw value. + fn into_raw_socketlike(self) -> RawSocketlike; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: IntoRawFd> IntoRawSocketlike for T { + #[inline] + fn into_raw_socketlike(self) -> RawSocketlike { + self.into_raw_fd() + } +} + +/// This is a portability abstraction over Unix-like `IntoRawFd` and Windows' +/// [`IntoRawSocket`]. +#[cfg(windows)] +pub trait IntoRawSocketlike: IntoRawSocket { + /// Returns the raw value. + fn into_raw_socketlike(self) -> RawSocketlike; +} + +#[cfg(windows)] +impl<T: IntoRawSocket> IntoRawSocketlike for T { + #[inline] + fn into_raw_socketlike(self) -> RawSocketlike { + self.into_raw_socket() + } +} + +/// This is a portability abstraction over Unix-like [`FromRawFd`] and Windows' +/// `FromRawHandle`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait FromRawFilelike: FromRawFd { + /// Constructs `Self` from the raw value. + /// + /// # Safety + /// + /// This is `unsafe` for the same reason as [`from_raw_fd`] and + /// [`from_raw_handle`]. + /// + /// [`from_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.from_raw_fd + /// [`from_raw_handle`]: https://doc.rust-lang.org/stable/std/os/windows/io/trait.FromRawHandle.html#tymethod.from_raw_handle + unsafe fn from_raw_filelike(raw: RawFilelike) -> Self; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: FromRawFd> FromRawFilelike for T { + #[inline] + unsafe fn from_raw_filelike(raw: RawFilelike) -> Self { + Self::from_raw_fd(raw) + } +} + +/// This is a portability abstraction over Unix-like `FromRawFd` and Windows' +/// [`FromRawHandle`]. +#[cfg(windows)] +pub trait FromRawFilelike: FromRawHandle { + /// Constructs `Self` from the raw value. + unsafe fn from_raw_filelike(raw: RawFilelike) -> Self; +} + +#[cfg(windows)] +impl<T: FromRawHandle> FromRawFilelike for T { + #[inline] + unsafe fn from_raw_filelike(raw: RawFilelike) -> Self { + Self::from_raw_handle(raw) + } +} + +/// This is a portability abstraction over Unix-like [`FromRawFd`] and Windows' +/// `FromRawSocket`. +#[cfg(any(unix, target_os = "wasi"))] +pub trait FromRawSocketlike: FromRawFd { + /// Constructs `Self` from the raw value. + /// + /// # Safety + /// + /// This is `unsafe` for the same reason as [`from_raw_fd`] and + /// [`from_raw_socket`]. + /// + /// [`from_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.from_raw_fd + /// [`from_raw_socket`]: https://doc.rust-lang.org/stable/std/os/windows/io/trait.FromRawSocket.html#tymethod.from_raw_socket + unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self; +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<T: FromRawFd> FromRawSocketlike for T { + #[inline] + unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self { + Self::from_raw_fd(raw) + } +} + +/// This is a portability abstraction over Unix-like `FromRawFd` and Windows' +/// [`FromRawSocket`]. +#[cfg(windows)] +pub trait FromRawSocketlike: FromRawSocket { + /// Constructs `Self` from the raw value. + unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self; +} + +#[cfg(windows)] +impl<T: FromRawSocket> FromRawSocketlike for T { + #[inline] + unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self { + Self::from_raw_socket(raw) + } +} diff --git a/vendor/io-lifetimes/src/traits.rs b/vendor/io-lifetimes/src/traits.rs new file mode 100644 index 000000000..788045208 --- /dev/null +++ b/vendor/io-lifetimes/src/traits.rs @@ -0,0 +1,274 @@ +#[cfg(not(io_lifetimes_use_std))] +#[cfg(any(unix, target_os = "wasi"))] +use crate::BorrowedFd; +#[cfg(any(unix, target_os = "wasi"))] +use crate::OwnedFd; +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +use crate::{BorrowedHandle, BorrowedSocket}; +#[cfg(windows)] +use crate::{OwnedHandle, OwnedSocket}; + +/// A trait to borrow the file descriptor from an underlying object. +/// +/// This is only available on unix platforms and must be imported in order to +/// call the method. Windows platforms have a corresponding `AsHandle` and +/// `AsSocket` set of traits. +#[cfg(not(io_lifetimes_use_std))] +#[cfg(any(unix, target_os = "wasi"))] +pub trait AsFd { + /// Borrows the file descriptor. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{AsFd, BorrowedFd}; + /// + /// let mut f = File::open("foo.txt")?; + /// let borrowed_fd: BorrowedFd<'_> = f.as_fd(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn as_fd(&self) -> BorrowedFd<'_>; +} + +/// A trait to borrow the handle from an underlying object. +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +pub trait AsHandle { + /// Borrows the handle. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{AsHandle, BorrowedHandle}; + /// + /// let mut f = File::open("foo.txt")?; + /// let borrowed_handle: BorrowedHandle<'_> = f.as_handle(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn as_handle(&self) -> BorrowedHandle<'_>; +} + +/// A trait to borrow the socket from an underlying object. +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +pub trait AsSocket { + /// Borrows the socket. + fn as_socket(&self) -> BorrowedSocket<'_>; +} + +/// A trait to express the ability to consume an object and acquire ownership +/// of its file descriptor. +#[cfg(any(unix, target_os = "wasi"))] +pub trait IntoFd { + /// Consumes this object, returning the underlying file descriptor. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{IntoFd, OwnedFd}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_fd: OwnedFd = f.into_fd(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn into_fd(self) -> OwnedFd; +} + +/// A trait to express the ability to consume an object and acquire ownership +/// of its handle. +#[cfg(windows)] +pub trait IntoHandle { + /// Consumes this object, returning the underlying handle. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{IntoHandle, OwnedHandle}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_handle: OwnedHandle = f.into_handle(); + /// # Ok::<(), io::Error>(()) + /// ``` + fn into_handle(self) -> OwnedHandle; +} + +/// A trait to express the ability to consume an object and acquire ownership +/// of its socket. +#[cfg(windows)] +pub trait IntoSocket { + /// Consumes this object, returning the underlying socket. + fn into_socket(self) -> OwnedSocket; +} + +/// A trait to express the ability to construct an object from a file +/// descriptor. +#[cfg(any(unix, target_os = "wasi"))] +pub trait FromFd { + /// Constructs a new instance of `Self` from the given file descriptor. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromFd, IntoFd, OwnedFd}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_fd: OwnedFd = f.into_fd(); + /// let f = File::from_fd(owned_fd); + /// # Ok::<(), io::Error>(()) + /// ``` + fn from_fd(owned: OwnedFd) -> Self; + + /// Constructs a new instance of `Self` from the given file descriptor + /// converted from `into_owned`. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromFd, IntoFd}; + /// + /// let f = File::open("foo.txt")?; + /// let f = File::from_into_fd(f); + /// # Ok::<(), io::Error>(()) + /// ``` + #[inline] + fn from_into_fd<Owned: IntoFd>(into_owned: Owned) -> Self + where + Self: Sized, + { + Self::from_fd(into_owned.into_fd()) + } +} + +/// A trait to express the ability to construct an object from a handle. +#[cfg(windows)] +pub trait FromHandle { + /// Constructs a new instance of `Self` from the given handle. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromHandle, IntoHandle, OwnedHandle}; + /// + /// let f = File::open("foo.txt")?; + /// let owned_handle: OwnedHandle = f.into_handle(); + /// let f = File::from_handle(owned_handle); + /// # Ok::<(), io::Error>(()) + /// ``` + fn from_handle(owned: OwnedHandle) -> Self; + + /// Constructs a new instance of `Self` from the given handle converted + /// from `into_owned`. + /// + /// # Example + /// + /// ```rust,no_run + /// # #![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + /// use std::fs::File; + /// # use std::io; + /// use io_lifetimes::{FromHandle, IntoHandle}; + /// + /// let f = File::open("foo.txt")?; + /// let f = File::from_into_handle(f); + /// # Ok::<(), io::Error>(()) + /// ``` + #[inline] + fn from_into_handle<Owned: IntoHandle>(into_owned: Owned) -> Self + where + Self: Sized, + { + Self::from_handle(into_owned.into_handle()) + } +} + +/// A trait to express the ability to construct an object from a socket. +#[cfg(windows)] +pub trait FromSocket { + /// Constructs a new instance of `Self` from the given socket. + fn from_socket(owned: OwnedSocket) -> Self; + + /// Constructs a new instance of `Self` from the given socket converted + /// from `into_owned`. + #[inline] + fn from_into_socket<Owned: IntoSocket>(into_owned: Owned) -> Self + where + Self: Sized, + { + Self::from_socket(into_owned.into_socket()) + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(any(unix, target_os = "wasi"))] +impl<T: AsFd> AsFd for &T { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + T::as_fd(self) + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(any(unix, target_os = "wasi"))] +impl<T: AsFd> AsFd for &mut T { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + T::as_fd(self) + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +impl<T: AsHandle> AsHandle for &T { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + T::as_handle(self) + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +impl<T: AsHandle> AsHandle for &mut T { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + T::as_handle(self) + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +impl<T: AsSocket> AsSocket for &T { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + T::as_socket(self) + } +} + +#[cfg(not(io_lifetimes_use_std))] +#[cfg(windows)] +impl<T: AsSocket> AsSocket for &mut T { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + T::as_socket(self) + } +} diff --git a/vendor/io-lifetimes/src/types.rs b/vendor/io-lifetimes/src/types.rs new file mode 100644 index 000000000..695ae513c --- /dev/null +++ b/vendor/io-lifetimes/src/types.rs @@ -0,0 +1,894 @@ +use std::fmt; +use std::marker::PhantomData; +use std::mem::forget; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +#[cfg(windows)] +use std::{ + convert::TryFrom, + os::windows::io::{ + AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket, + RawHandle, RawSocket, + }, +}; +#[cfg(all(windows, feature = "close"))] +use { + windows_sys::Win32::Foundation::{ + CloseHandle, DuplicateHandle, SetHandleInformation, BOOL, DUPLICATE_HANDLE_OPTIONS, + DUPLICATE_SAME_ACCESS, HANDLE, HANDLE_FLAG_INHERIT, INVALID_HANDLE_VALUE, + }, + windows_sys::Win32::Networking::WinSock::{ + closesocket, WSADuplicateSocketW, WSAGetLastError, WSASocketW, INVALID_SOCKET, SOCKET, + SOCKET_ERROR, WSAEINVAL, WSAEPROTOTYPE, WSAPROTOCOL_INFOW, WSA_FLAG_NO_HANDLE_INHERIT, + WSA_FLAG_OVERLAPPED, + }, + windows_sys::Win32::System::Threading::{GetCurrentProcess, GetCurrentProcessId}, +}; + +#[cfg(all(windows, not(feature = "close")))] +type HANDLE = isize; +#[cfg(all(windows, not(feature = "close")))] +const INVALID_HANDLE_VALUE: HANDLE = !0 as _; +#[cfg(all(windows, not(feature = "close")))] +const INVALID_SOCKET: usize = !0 as _; + +/// A borrowed file descriptor. +/// +/// This has a lifetime parameter to tie it to the lifetime of something that +/// owns the file descriptor. +/// +/// This uses `repr(transparent)` and has the representation of a host file +/// descriptor, so it can be used in FFI in places where a file descriptor is +/// passed as an argument, it is not captured or consumed, and it never has the +/// value `-1`. +/// +/// This type's `.to_owned()` implementation returns another `BorrowedFd` +/// rather than an `OwnedFd`. It just makes a trivial copy of the raw file +/// descriptor, which is then borrowed under the same lifetime. +#[cfg(any(unix, target_os = "wasi"))] +#[derive(Copy, Clone)] +#[repr(transparent)] +#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] +#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] +// libstd/os/raw/mod.rs assures me that every libstd-supported platform has a +// 32-bit c_int. Below is -2, in two's complement, but that only works out +// because c_int is 32 bits. +#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE))] +pub struct BorrowedFd<'fd> { + fd: RawFd, + _phantom: PhantomData<&'fd OwnedFd>, +} + +/// A borrowed handle. +/// +/// This has a lifetime parameter to tie it to the lifetime of something that +/// owns the handle. +/// +/// This uses `repr(transparent)` and has the representation of a host handle, +/// so it can be used in FFI in places where a handle is passed as an argument, +/// it is not captured or consumed, and it is never null. +/// +/// Note that it *may* have the value `-1`, which in `BorrowedHandle` always +/// represents a valid handle value, such as [the current process handle], and +/// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See +/// [here] for the full story. +/// +/// This type's `.to_owned()` implementation returns another `BorrowedHandle` +/// rather than an `OwnedHandle`. It just makes a trivial copy of the raw +/// handle, which is then borrowed under the same lifetime. +/// +/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 +/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks +#[cfg(windows)] +#[derive(Copy, Clone)] +#[repr(transparent)] +pub struct BorrowedHandle<'handle> { + handle: RawHandle, + _phantom: PhantomData<&'handle OwnedHandle>, +} + +/// A borrowed socket. +/// +/// This has a lifetime parameter to tie it to the lifetime of something that +/// owns the socket. +/// +/// This uses `repr(transparent)` and has the representation of a host socket, +/// so it can be used in FFI in places where a socket is passed as an argument, +/// it is not captured or consumed, and it never has the value +/// [`INVALID_SOCKET`]. +/// +/// This type's `.to_owned()` implementation returns another `BorrowedSocket` +/// rather than an `OwnedSocket`. It just makes a trivial copy of the raw +/// socket, which is then borrowed under the same lifetime. +#[cfg(windows)] +#[derive(Copy, Clone)] +#[repr(transparent)] +#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] +#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] +// This is -2, in two's complement. -1 is `INVALID_SOCKET`. +#[cfg_attr( + all(rustc_attrs, target_pointer_width = "32"), + rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE) +)] +#[cfg_attr( + all(rustc_attrs, target_pointer_width = "64"), + rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE) +)] +pub struct BorrowedSocket<'socket> { + socket: RawSocket, + _phantom: PhantomData<&'socket OwnedSocket>, +} + +/// An owned file descriptor. +/// +/// This closes the file descriptor on drop. +/// +/// This uses `repr(transparent)` and has the representation of a host file +/// descriptor, so it can be used in FFI in places where a file descriptor is +/// passed as a consumed argument or returned as an owned value, and it never +/// has the value `-1`. +#[cfg(any(unix, target_os = "wasi"))] +#[repr(transparent)] +#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] +#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] +// libstd/os/raw/mod.rs assures me that every libstd-supported platform has a +// 32-bit c_int. Below is -2, in two's complement, but that only works out +// because c_int is 32 bits. +#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE))] +pub struct OwnedFd { + fd: RawFd, +} + +#[cfg(any(unix, target_os = "wasi"))] +impl OwnedFd { + /// Creates a new `OwnedFd` instance that shares the same underlying file + /// description as the existing `OwnedFd` instance. + pub fn try_clone(&self) -> std::io::Result<Self> { + crate::AsFd::as_fd(self).try_clone_to_owned() + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl BorrowedFd<'_> { + /// Creates a new `OwnedFd` instance that shares the same underlying file + /// description as the existing `BorrowedFd` instance. + pub fn try_clone_to_owned(&self) -> std::io::Result<OwnedFd> { + #[cfg(feature = "close")] + { + #[cfg(unix)] + { + // We want to atomically duplicate this file descriptor and set the + // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This + // is a POSIX flag that was added to Linux in 2.6.24. + #[cfg(not(target_os = "espidf"))] + let cmd = libc::F_DUPFD_CLOEXEC; + + // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics + // will never be supported, as this is a bare metal framework with + // no capabilities for multi-process execution. While F_DUPFD is also + // not supported yet, it might be (currently it returns ENOSYS). + #[cfg(target_os = "espidf")] + let cmd = libc::F_DUPFD; + + let fd = match unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) } { + -1 => return Err(std::io::Error::last_os_error()), + fd => fd, + }; + + Ok(unsafe { OwnedFd::from_raw_fd(fd) }) + } + + #[cfg(target_os = "wasi")] + { + unreachable!("try_clone is not yet suppported on wasi"); + } + } + + // If the `close` feature is disabled, we expect users to avoid cloning + // `OwnedFd` instances, so that we don't have to call `fcntl`. + #[cfg(not(feature = "close"))] + { + unreachable!("try_clone called without the \"close\" feature in io-lifetimes"); + } + } +} + +/// An owned handle. +/// +/// This closes the handle on drop. +/// +/// Note that it *may* have the value `-1`, which in `OwnedHandle` always +/// represents a valid handle value, such as [the current process handle], and +/// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See +/// [here] for the full story. +/// +/// And, it *may* have the value `NULL` (0), which can occur when consoles are +/// detached from processes, or when `windows_subsystem` is used. +/// +/// `OwnedHandle` uses [`CloseHandle`] to close its handle on drop. As such, +/// it must not be used with handles to open registry keys which need to be +/// closed with [`RegCloseKey`] instead. +/// +/// [`CloseHandle`]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle +/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey +/// +/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 +/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks +#[cfg(windows)] +#[repr(transparent)] +pub struct OwnedHandle { + handle: RawHandle, +} + +#[cfg(windows)] +impl OwnedHandle { + /// Creates a new `OwnedHandle` instance that shares the same underlying + /// object as the existing `OwnedHandle` instance. + pub fn try_clone(&self) -> std::io::Result<Self> { + crate::AsHandle::as_handle(self).try_clone_to_owned() + } +} + +#[cfg(windows)] +impl BorrowedHandle<'_> { + /// Creates a new `OwnedHandle` instance that shares the same underlying + /// object as the existing `BorrowedHandle` instance. + pub fn try_clone_to_owned(&self) -> std::io::Result<OwnedHandle> { + #[cfg(feature = "close")] + { + self.duplicate(0, false, DUPLICATE_SAME_ACCESS) + } + + // If the `close` feature is disabled, we expect users to avoid cloning + // `OwnedHandle` instances, so that we don't have to call `fcntl`. + #[cfg(not(feature = "close"))] + { + unreachable!("try_clone called without the \"close\" feature in io-lifetimes"); + } + } + + #[cfg(feature = "close")] + pub(crate) fn duplicate( + &self, + access: u32, + inherit: bool, + options: DUPLICATE_HANDLE_OPTIONS, + ) -> std::io::Result<OwnedHandle> { + let mut ret = 0 as HANDLE; + match unsafe { + let cur_proc = GetCurrentProcess(); + DuplicateHandle( + cur_proc, + self.as_raw_handle() as HANDLE, + cur_proc, + &mut ret, + access, + inherit as BOOL, + options, + ) + } { + 0 => return Err(std::io::Error::last_os_error()), + _ => (), + } + unsafe { Ok(OwnedHandle::from_raw_handle(ret as RawHandle)) } + } +} + +/// An owned socket. +/// +/// This closes the socket on drop. +/// +/// This uses `repr(transparent)` and has the representation of a host socket, +/// so it can be used in FFI in places where a socket is passed as a consumed +/// argument or returned as an owned value, and it never has the value +/// [`INVALID_SOCKET`]. +#[cfg(windows)] +#[repr(transparent)] +#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)] +#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_start(0))] +// This is -2, in two's complement. -1 is `INVALID_SOCKET`. +#[cfg_attr( + all(rustc_attrs, target_pointer_width = "32"), + rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE) +)] +#[cfg_attr( + all(rustc_attrs, target_pointer_width = "64"), + rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE) +)] +pub struct OwnedSocket { + socket: RawSocket, +} + +#[cfg(windows)] +impl OwnedSocket { + /// Creates a new `OwnedSocket` instance that shares the same underlying + /// object as the existing `OwnedSocket` instance. + pub fn try_clone(&self) -> std::io::Result<Self> { + crate::AsSocket::as_socket(self).try_clone_to_owned() + } + + #[cfg(feature = "close")] + #[cfg(not(target_vendor = "uwp"))] + fn set_no_inherit(&self) -> std::io::Result<()> { + match unsafe { + SetHandleInformation(self.as_raw_socket() as HANDLE, HANDLE_FLAG_INHERIT, 0) + } { + 0 => return Err(std::io::Error::last_os_error()), + _ => Ok(()), + } + } + + #[cfg(feature = "close")] + #[cfg(target_vendor = "uwp")] + fn set_no_inherit(&self) -> std::io::Result<()> { + Err(io::Error::new_const( + std::io::ErrorKind::Unsupported, + &"Unavailable on UWP", + )) + } +} + +#[cfg(windows)] +impl BorrowedSocket<'_> { + /// Creates a new `OwnedSocket` instance that shares the same underlying + /// object as the existing `BorrowedSocket` instance. + pub fn try_clone_to_owned(&self) -> std::io::Result<OwnedSocket> { + #[cfg(feature = "close")] + { + let mut info = unsafe { std::mem::zeroed::<WSAPROTOCOL_INFOW>() }; + let result = unsafe { + WSADuplicateSocketW(self.as_raw_socket() as _, GetCurrentProcessId(), &mut info) + }; + match result { + SOCKET_ERROR => return Err(std::io::Error::last_os_error()), + 0 => (), + _ => panic!(), + } + let socket = unsafe { + WSASocketW( + info.iAddressFamily, + info.iSocketType, + info.iProtocol, + &mut info, + 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT, + ) + }; + + if socket != INVALID_SOCKET { + unsafe { Ok(OwnedSocket::from_raw_socket(socket as _)) } + } else { + let error = unsafe { WSAGetLastError() }; + + if error != WSAEPROTOTYPE && error != WSAEINVAL { + return Err(std::io::Error::from_raw_os_error(error)); + } + + let socket = unsafe { + WSASocketW( + info.iAddressFamily, + info.iSocketType, + info.iProtocol, + &mut info, + 0, + WSA_FLAG_OVERLAPPED, + ) + }; + + if socket == INVALID_SOCKET { + return Err(std::io::Error::last_os_error()); + } + + unsafe { + let socket = OwnedSocket::from_raw_socket(socket as _); + socket.set_no_inherit()?; + Ok(socket) + } + } + } + + // If the `close` feature is disabled, we expect users to avoid cloning + // `OwnedSocket` instances, so that we don't have to call `fcntl`. + #[cfg(not(feature = "close"))] + { + unreachable!("try_clone called without the \"close\" feature in io-lifetimes"); + } + } +} + +/// FFI type for handles in return values or out parameters, where `INVALID_HANDLE_VALUE` is used +/// as a sentry value to indicate errors, such as in the return value of `CreateFileW`. This uses +/// `repr(transparent)` and has the representation of a host handle, so that it can be used in such +/// FFI declarations. +/// +/// The only thing you can usefully do with a `HandleOrInvalid` is to convert it into an +/// `OwnedHandle` using its [`TryFrom`] implementation; this conversion takes care of the check for +/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without +/// checking for `INVALID_HANDLE_VALUE` first. +/// +/// This type may hold any handle value that [`OwnedHandle`] may hold, except that when it holds +/// `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`. +/// +/// If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. +#[cfg(windows)] +#[repr(transparent)] +#[derive(Debug)] +pub struct HandleOrInvalid(RawHandle); + +/// FFI type for handles in return values or out parameters, where `NULL` is used +/// as a sentry value to indicate errors, such as in the return value of `CreateThread`. This uses +/// `repr(transparent)` and has the representation of a host handle, so that it can be used in such +/// FFI declarations. +/// +/// The only thing you can usefully do with a `HandleOrNull` is to convert it into an +/// `OwnedHandle` using its [`TryFrom`] implementation; this conversion takes care of the check for +/// `NULL`. This ensures that such FFI calls cannot start using the handle without +/// checking for `NULL` first. +/// +/// This type may hold any handle value that [`OwnedHandle`] may hold. As with `OwnedHandle`, when +/// it holds `-1`, that value is interpreted as a valid handle value, such as +/// [the current process handle], and not `INVALID_HANDLE_VALUE`. +/// +/// If this holds a non-null handle, it will close the handle on drop. +/// +/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks +#[cfg(windows)] +#[repr(transparent)] +#[derive(Debug)] +pub struct HandleOrNull(RawHandle); + +// The Windows [`HANDLE`] type may be transferred across and shared between +// thread boundaries (despite containing a `*mut void`, which in general isn't +// `Send` or `Sync`). +// +// [`HANDLE`]: std::os::windows::raw::HANDLE +#[cfg(windows)] +unsafe impl Send for OwnedHandle {} +#[cfg(windows)] +unsafe impl Send for HandleOrInvalid {} +#[cfg(windows)] +unsafe impl Send for HandleOrNull {} +#[cfg(windows)] +unsafe impl Send for BorrowedHandle<'_> {} +#[cfg(windows)] +unsafe impl Sync for OwnedHandle {} +#[cfg(windows)] +unsafe impl Sync for HandleOrInvalid {} +#[cfg(windows)] +unsafe impl Sync for HandleOrNull {} +#[cfg(windows)] +unsafe impl Sync for BorrowedHandle<'_> {} + +#[cfg(any(unix, target_os = "wasi"))] +impl BorrowedFd<'_> { + /// Return a `BorrowedFd` holding the given raw file descriptor. + /// + /// # Safety + /// + /// The resource pointed to by `raw` must remain open for the duration of + /// the returned `BorrowedFd`, and it must not have the value `-1`. + #[inline] + pub const unsafe fn borrow_raw(fd: RawFd) -> Self { + #[cfg(panic_in_const_fn)] + debug_assert!(fd != -1_i32 as RawFd); + + Self { + fd, + _phantom: PhantomData, + } + } +} + +#[cfg(windows)] +impl BorrowedHandle<'_> { + /// Return a `BorrowedHandle` holding the given raw handle. + /// + /// # Safety + /// + /// The resource pointed to by `handle` must be a valid open handle, it + /// must remain open for the duration of the returned `BorrowedHandle`. + /// + /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is + /// sometimes a valid handle value. See [here] for the full story. + /// + /// And, it *may* have the value `NULL` (0), which can occur when consoles are + /// detached from processes, or when `windows_subsystem` is used. + /// + /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 + #[inline] + pub const unsafe fn borrow_raw(handle: RawHandle) -> Self { + Self { + handle, + _phantom: PhantomData, + } + } +} + +#[cfg(windows)] +impl BorrowedSocket<'_> { + /// Return a `BorrowedSocket` holding the given raw socket. + /// + /// # Safety + /// + /// The resource pointed to by `raw` must remain open for the duration of + /// the returned `BorrowedSocket`, and it must not have the value + /// [`INVALID_SOCKET`]. + #[inline] + pub const unsafe fn borrow_raw(socket: RawSocket) -> Self { + #[cfg(panic_in_const_fn)] + debug_assert!(socket != INVALID_SOCKET as RawSocket); + Self { + socket, + _phantom: PhantomData, + } + } +} + +#[cfg(windows)] +impl TryFrom<HandleOrInvalid> for OwnedHandle { + type Error = InvalidHandleError; + + #[inline] + fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleError> { + let raw = handle_or_invalid.0; + if raw as HANDLE == INVALID_HANDLE_VALUE { + // Don't call `CloseHandle`; it'd be harmless, except that it could + // overwrite the `GetLastError` error. + forget(handle_or_invalid); + + Err(InvalidHandleError(())) + } else { + Ok(OwnedHandle { handle: raw }) + } + } +} + +#[cfg(windows)] +impl TryFrom<HandleOrNull> for OwnedHandle { + type Error = NullHandleError; + + #[inline] + fn try_from(handle_or_null: HandleOrNull) -> Result<Self, NullHandleError> { + let raw = handle_or_null.0; + if raw.is_null() { + // Don't call `CloseHandle`; it'd be harmless, except that it could + // overwrite the `GetLastError` error. + forget(handle_or_null); + + Err(NullHandleError(())) + } else { + Ok(OwnedHandle { handle: raw }) + } + } +} + +/// This is the error type used by [`HandleOrNull`] when attempting to convert +/// into a handle, to indicate that the value is null. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct NullHandleError(()); + +impl fmt::Display for NullHandleError { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + "A HandleOrNull could not be converted to a handle because it was null".fmt(fmt) + } +} + +impl std::error::Error for NullHandleError {} + +/// This is the error type used by [`HandleOrInvalid`] when attempting to +/// convert into a handle, to indicate that the value is +/// `INVALID_HANDLE_VALUE`. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct InvalidHandleError(()); + +impl fmt::Display for InvalidHandleError { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + "A HandleOrInvalid could not be converted to a handle because it was INVALID_HANDLE_VALUE" + .fmt(fmt) + } +} + +impl std::error::Error for InvalidHandleError {} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsRawFd for BorrowedFd<'_> { + #[inline] + fn as_raw_fd(&self) -> RawFd { + self.fd + } +} + +#[cfg(windows)] +impl AsRawHandle for BorrowedHandle<'_> { + #[inline] + fn as_raw_handle(&self) -> RawHandle { + self.handle + } +} + +#[cfg(windows)] +impl AsRawSocket for BorrowedSocket<'_> { + #[inline] + fn as_raw_socket(&self) -> RawSocket { + self.socket + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsRawFd for OwnedFd { + #[inline] + fn as_raw_fd(&self) -> RawFd { + self.fd + } +} + +#[cfg(windows)] +impl AsRawHandle for OwnedHandle { + #[inline] + fn as_raw_handle(&self) -> RawHandle { + self.handle + } +} + +#[cfg(windows)] +impl AsRawSocket for OwnedSocket { + #[inline] + fn as_raw_socket(&self) -> RawSocket { + self.socket + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoRawFd for OwnedFd { + #[inline] + fn into_raw_fd(self) -> RawFd { + let fd = self.fd; + forget(self); + fd + } +} + +#[cfg(windows)] +impl IntoRawHandle for OwnedHandle { + #[inline] + fn into_raw_handle(self) -> RawHandle { + let handle = self.handle; + forget(self); + handle + } +} + +#[cfg(windows)] +impl IntoRawSocket for OwnedSocket { + #[inline] + fn into_raw_socket(self) -> RawSocket { + let socket = self.socket; + forget(self); + socket + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromRawFd for OwnedFd { + /// Constructs a new instance of `Self` from the given raw file descriptor. + /// + /// # Safety + /// + /// The resource pointed to by `raw` must be open and suitable for assuming + /// ownership. + #[inline] + unsafe fn from_raw_fd(fd: RawFd) -> Self { + debug_assert_ne!(fd, -1_i32 as RawFd); + Self { fd } + } +} + +#[cfg(windows)] +impl FromRawHandle for OwnedHandle { + #[inline] + unsafe fn from_raw_handle(handle: RawHandle) -> Self { + Self { handle } + } +} + +#[cfg(windows)] +impl FromRawSocket for OwnedSocket { + #[inline] + unsafe fn from_raw_socket(socket: RawSocket) -> Self { + debug_assert_ne!(socket, INVALID_SOCKET as RawSocket); + Self { socket } + } +} + +#[cfg(windows)] +impl HandleOrInvalid { + /// Constructs a new instance of `Self` from the given `RawHandle` returned + /// from a Windows API that uses `INVALID_HANDLE_VALUE` to indicate + /// failure, such as `CreateFileW`. + /// + /// Use `HandleOrNull` instead of `HandleOrInvalid` for APIs that + /// use null to indicate failure. + /// + /// # Safety + /// + /// The passed `handle` value must either satisfy the safety requirements + /// of [`FromRawHandle::from_raw_handle`], or be + /// `INVALID_HANDLE_VALUE` (-1). Note that not all Windows APIs use + /// `INVALID_HANDLE_VALUE` for errors; see [here] for the full story. + /// + /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 + #[inline] + pub unsafe fn from_raw_handle(handle: RawHandle) -> Self { + Self(handle) + } +} + +#[cfg(windows)] +impl HandleOrNull { + /// Constructs a new instance of `Self` from the given `RawHandle` returned + /// from a Windows API that uses null to indicate failure, such as + /// `CreateThread`. + /// + /// Use `HandleOrInvalid` instead of `HandleOrNull` for APIs that + /// use `INVALID_HANDLE_VALUE` to indicate failure. + /// + /// # Safety + /// + /// The passed `handle` value must either satisfy the safety requirements + /// of [`FromRawHandle::from_raw_handle`], or be null. Note that not all + /// Windows APIs use null for errors; see [here] for the full story. + /// + /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443 + #[inline] + pub unsafe fn from_raw_handle(handle: RawHandle) -> Self { + Self(handle) + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl Drop for OwnedFd { + #[inline] + fn drop(&mut self) { + #[cfg(feature = "close")] + unsafe { + let _ = libc::close(self.fd as std::os::raw::c_int); + } + + // If the `close` feature is disabled, we expect users to avoid letting + // `OwnedFd` instances drop, so that we don't have to call `close`. + #[cfg(not(feature = "close"))] + { + unreachable!("drop called without the \"close\" feature in io-lifetimes"); + } + } +} + +#[cfg(windows)] +impl Drop for OwnedHandle { + #[inline] + fn drop(&mut self) { + #[cfg(feature = "close")] + unsafe { + let _ = CloseHandle(self.handle as HANDLE); + } + + // If the `close` feature is disabled, we expect users to avoid letting + // `OwnedHandle` instances drop, so that we don't have to call `close`. + #[cfg(not(feature = "close"))] + { + unreachable!("drop called without the \"close\" feature in io-lifetimes"); + } + } +} + +#[cfg(windows)] +impl Drop for HandleOrInvalid { + #[inline] + fn drop(&mut self) { + #[cfg(feature = "close")] + unsafe { + let _ = CloseHandle(self.0 as HANDLE); + } + + // If the `close` feature is disabled, we expect users to avoid letting + // `HandleOrInvalid` instances drop, so that we don't have to call `close`. + #[cfg(not(feature = "close"))] + { + unreachable!("drop called without the \"close\" feature in io-lifetimes"); + } + } +} + +#[cfg(windows)] +impl Drop for HandleOrNull { + #[inline] + fn drop(&mut self) { + #[cfg(feature = "close")] + unsafe { + let _ = CloseHandle(self.0 as HANDLE); + } + + // If the `close` feature is disabled, we expect users to avoid letting + // `HandleOrNull` instances drop, so that we don't have to call `close`. + #[cfg(not(feature = "close"))] + { + unreachable!("drop called without the \"close\" feature in io-lifetimes"); + } + } +} + +#[cfg(windows)] +impl Drop for OwnedSocket { + #[inline] + fn drop(&mut self) { + #[cfg(feature = "close")] + unsafe { + let _ = closesocket(self.socket as SOCKET); + } + + // If the `close` feature is disabled, we expect users to avoid letting + // `OwnedSocket` instances drop, so that we don't have to call `close`. + #[cfg(not(feature = "close"))] + { + unreachable!("drop called without the \"close\" feature in io-lifetimes"); + } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl fmt::Debug for BorrowedFd<'_> { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("BorrowedFd").field("fd", &self.fd).finish() + } +} + +#[cfg(windows)] +impl fmt::Debug for BorrowedHandle<'_> { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("BorrowedHandle") + .field("handle", &self.handle) + .finish() + } +} + +#[cfg(windows)] +impl fmt::Debug for BorrowedSocket<'_> { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("BorrowedSocket") + .field("socket", &self.socket) + .finish() + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl fmt::Debug for OwnedFd { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("OwnedFd").field("fd", &self.fd).finish() + } +} + +#[cfg(windows)] +impl fmt::Debug for OwnedHandle { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("OwnedHandle") + .field("handle", &self.handle) + .finish() + } +} + +#[cfg(windows)] +impl fmt::Debug for OwnedSocket { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("OwnedSocket") + .field("socket", &self.socket) + .finish() + } +} diff --git a/vendor/io-lifetimes/src/views.rs b/vendor/io-lifetimes/src/views.rs new file mode 100644 index 000000000..aec3750a0 --- /dev/null +++ b/vendor/io-lifetimes/src/views.rs @@ -0,0 +1,204 @@ +//! Typed views using temporary objects. +//! +//! This module defines the return types for [`AsFilelike::as_filelike_view`] +//! and [`AsSocketlike::as_socketlike_view`]. +//! +//! [`AsSocketlike::as_socketlike_view`]: crate::AsSocketlike::as_socketlike_view + +use crate::raw::{ + AsRawFilelike, AsRawSocketlike, FromRawFilelike, FromRawSocketlike, IntoRawFilelike, + IntoRawSocketlike, RawFilelike, RawSocketlike, +}; +use crate::{ + AsFilelike, AsSocketlike, FromFilelike, FromSocketlike, IntoFilelike, IntoSocketlike, + OwnedFilelike, OwnedSocketlike, +}; +use std::fmt; +use std::marker::PhantomData; +use std::mem::ManuallyDrop; +use std::ops::Deref; + +/// Declare that a type is safe to use in a [`FilelikeView`]. +/// +/// # Safety +/// +/// Types implementing this trait declare that if they are constructed with +/// [`FromFilelike`] and consumed with [`IntoFilelike`], their `IntoFilelike` +/// will return the same `OwnedFd` value that was passed to their +/// `FromFilelike`. +pub unsafe trait FilelikeViewType: FromFilelike + IntoFilelike {} + +/// Declare that a type is safe to use in a [`SocketlikeView`]. +/// +/// # Safety +/// +/// Types implementing this trait declare that if they are constructed with +/// [`FromSocketlike`] and consumed with [`IntoSocketlike`], their +/// `IntoSocketlike` will return the same `OwnedFd` value that was passed to +/// their `FromSocketlike`. +pub unsafe trait SocketlikeViewType: FromSocketlike + IntoSocketlike {} + +/// A non-owning view of a resource which dereferences to a `&Target` or +/// `&mut Target`. These are returned by [`AsFilelike::as_filelike_view`]. +pub struct FilelikeView<'filelike, Target: FilelikeViewType> { + /// The value to dereference to. This is a `ManuallyDrop` so that we can + /// consume it in our `Drop` impl. + target: ManuallyDrop<Target>, + + /// `FilelikeViewType` implementors guarantee that their `Into<OwnedFd>` + /// returns the same fd as their `From<OwnedFd>` gave them. This field + /// allows us to verify this. + #[cfg(debug_assertions)] + orig: RawFilelike, + + /// This field exists because we don't otherwise explicitly use + /// `'filelike`. + _phantom: PhantomData<&'filelike OwnedFilelike>, +} + +/// A non-owning view of a resource which dereferences to a `&Target` or +/// `&mut Target`. These are returned by [`AsSocketlike::as_socketlike_view`]. +pub struct SocketlikeView<'socketlike, Target: SocketlikeViewType> { + /// The value to dereference to. This is a `ManuallyDrop` so that we can + /// consume it in our `Drop` impl. + target: ManuallyDrop<Target>, + + /// `SocketlikeViewType` implementors guarantee that their `Into<OwnedFd>` + /// returns the same fd as their `From<OwnedFd>` gave them. This field + /// allows us to verify this. + #[cfg(debug_assertions)] + orig: RawSocketlike, + + /// This field exists because we don't otherwise explicitly use + /// `'socketlike`. + _phantom: PhantomData<&'socketlike OwnedSocketlike>, +} + +impl<Target: FilelikeViewType> FilelikeView<'_, Target> { + /// Construct a temporary `Target` and wrap it in a `FilelikeView` object. + #[inline] + pub(crate) fn new<T: AsFilelike>(filelike: &T) -> Self { + // Safety: The returned `FilelikeView` is scoped to the lifetime of + // `filelike`, which we've borrowed here, so the view won't outlive + // the object it's borrowed from. + unsafe { Self::view_raw(filelike.as_filelike().as_raw_filelike()) } + } + + /// Construct a temporary `Target` from raw and wrap it in a `FilelikeView` + /// object. + /// + /// # Safety + /// + /// `raw` must be a valid raw filelike referencing a resource that outlives + /// the resulting view. + #[inline] + pub unsafe fn view_raw(raw: RawFilelike) -> Self { + let owned = OwnedFilelike::from_raw_filelike(raw); + Self { + target: ManuallyDrop::new(Target::from_filelike(owned)), + #[cfg(debug_assertions)] + orig: raw, + _phantom: PhantomData, + } + } +} + +impl<Target: SocketlikeViewType> SocketlikeView<'_, Target> { + /// Construct a temporary `Target` and wrap it in a `SocketlikeView` + /// object. + #[inline] + pub(crate) fn new<T: AsSocketlike>(socketlike: &T) -> Self { + // Safety: The returned `SocketlikeView` is scoped to the lifetime of + // `socketlike`, which we've borrowed here, so the view won't outlive + // the object it's borrowed from. + unsafe { Self::view_raw(socketlike.as_socketlike().as_raw_socketlike()) } + } + + /// Construct a temporary `Target` from raw and wrap it in a + /// `SocketlikeView` object. + /// + /// # Safety + /// + /// `raw` must be a valid raw socketlike referencing a resource that + /// outlives the resulting view. + #[inline] + pub unsafe fn view_raw(raw: RawSocketlike) -> Self { + let owned = OwnedSocketlike::from_raw_socketlike(raw); + Self { + target: ManuallyDrop::new(Target::from_socketlike(owned)), + #[cfg(debug_assertions)] + orig: raw, + _phantom: PhantomData, + } + } +} + +impl<Target: FilelikeViewType> Deref for FilelikeView<'_, Target> { + type Target = Target; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.target + } +} + +impl<Target: SocketlikeViewType> Deref for SocketlikeView<'_, Target> { + type Target = Target; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.target + } +} + +impl<Target: FilelikeViewType> Drop for FilelikeView<'_, Target> { + #[inline] + fn drop(&mut self) { + // Use `Into*` to consume `self.target` without freeing its resource. + // + // Safety: Using `ManuallyDrop::take` requires us to ensure that + // `self.target` is not used again. We don't use it again here, and + // this is the `drop` function, so we know it's not used afterward. + let _raw = unsafe { ManuallyDrop::take(&mut self.target) } + .into_filelike() + .into_raw_filelike(); + + #[cfg(debug_assertions)] + debug_assert_eq!(self.orig, _raw); + } +} + +impl<Target: SocketlikeViewType> Drop for SocketlikeView<'_, Target> { + #[inline] + fn drop(&mut self) { + // Use `Into*` to consume `self.target` without freeing its resource. + // + // Safety: Using `ManuallyDrop::take` requires us to ensure that + // `self.target` is not used again. We don't use it again here, and + // this is the `drop` function, so we know it's not used afterward. + let _raw = unsafe { ManuallyDrop::take(&mut self.target) } + .into_socketlike() + .into_raw_socketlike(); + + #[cfg(debug_assertions)] + debug_assert_eq!(self.orig, _raw); + } +} + +impl<Target: FilelikeViewType> fmt::Debug for FilelikeView<'_, Target> { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FilelikeView") + .field("target", &*self) + .finish() + } +} + +impl<Target: SocketlikeViewType> fmt::Debug for SocketlikeView<'_, Target> { + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SocketlikeView") + .field("target", &*self) + .finish() + } +} diff --git a/vendor/io-lifetimes/tests/api.rs b/vendor/io-lifetimes/tests/api.rs new file mode 100644 index 000000000..19f65c440 --- /dev/null +++ b/vendor/io-lifetimes/tests/api.rs @@ -0,0 +1,146 @@ +#![cfg_attr(target_os = "wasi", feature(wasi_ext))] +#![cfg(feature = "close")] +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +use io_lifetimes::raw::{AsRawFilelike, AsRawSocketlike}; +use io_lifetimes::views::{FilelikeView, SocketlikeView}; +use io_lifetimes::{ + AsFilelike, AsSocketlike, BorrowedFilelike, FromFilelike, FromSocketlike, IntoFilelike, + IntoSocketlike, +}; +use std::io::{Read, Write}; + +struct Tester {} +impl Tester { + fn use_file<Filelike: AsFilelike>(filelike: Filelike) { + let mut buf = Vec::new(); + + let filelike = filelike.as_filelike(); + + let view = filelike.as_filelike_view::<std::fs::File>(); + let _ = (&*view).read(&mut buf).is_ok(); + let _ = (&*view).write(&buf).is_ok(); + + let view = unsafe { + FilelikeView::<std::fs::File>::view_raw( + filelike + .as_filelike_view::<std::fs::File>() + .as_raw_filelike(), + ) + }; + let _ = (&*view).read(&mut buf).is_ok(); + let _ = (&*view).write(&buf).is_ok(); + + let _ = dbg!(filelike); + } + + fn use_socket<Socketlike: AsSocketlike>(socketlike: Socketlike) { + let mut buf = Vec::new(); + + let socketlike = socketlike.as_socketlike(); + let view = socketlike.as_socketlike_view::<std::net::TcpStream>(); + let _ = (&*view).read(&mut buf).is_ok(); + let _ = (&*view).write(&buf).is_ok(); + + let view = unsafe { + SocketlikeView::<std::net::TcpStream>::view_raw( + socketlike + .as_socketlike_view::<std::net::TcpStream>() + .as_raw_socketlike(), + ) + }; + let _ = (&*view).read(&mut buf).is_ok(); + let _ = (&*view).write(&buf).is_ok(); + + let _ = dbg!(socketlike); + } + + fn from_file<Filelike: IntoFilelike>(filelike: Filelike) { + let mut buf = Vec::new(); + + let filelike = filelike.into_filelike(); + let view = filelike.as_filelike_view::<std::fs::File>(); + let _ = (&*view).read(&mut buf).is_ok(); + let _ = (&*view).write(&buf).is_ok(); + drop(view); + + let _ = dbg!(&filelike); + let _ = std::fs::File::from_filelike(filelike); + } + + fn from_socket<Socketlike: IntoSocketlike>(socketlike: Socketlike) { + let mut buf = Vec::new(); + + let socketlike = socketlike.into_socketlike(); + let view = socketlike.as_socketlike_view::<std::net::TcpStream>(); + let _ = (&*view).read(&mut buf).is_ok(); + let _ = (&*view).write(&buf).is_ok(); + drop(view); + + let _ = dbg!(&socketlike); + let _ = std::net::TcpStream::from_socketlike(socketlike); + } + + fn from_into_file<Filelike: IntoFilelike>(filelike: Filelike) { + let _ = std::fs::File::from_into_filelike(filelike); + } + + fn from_into_socket<Socketlike: IntoSocketlike>(socketlike: Socketlike) { + let _ = std::net::TcpStream::from_into_socketlike(socketlike); + } +} + +#[test] +fn test_api() { + let file = std::fs::File::open("Cargo.toml").unwrap(); + Tester::use_file(&file); + Tester::use_file(file.as_filelike()); + Tester::use_file(&*file.as_filelike_view::<std::fs::File>()); + Tester::use_file(file.as_filelike_view::<std::fs::File>().as_filelike()); + + let socket = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + Tester::use_socket(&socket); + Tester::use_socket(socket.as_socketlike()); + Tester::use_socket(&*socket.as_socketlike_view::<std::net::TcpListener>()); + Tester::use_socket( + socket + .as_socketlike_view::<std::net::TcpListener>() + .as_socketlike(), + ); + + Tester::from_file(std::fs::File::open("Cargo.toml").unwrap().into_filelike()); + Tester::from_file( + std::fs::File::open("Cargo.toml") + .unwrap() + .into_filelike() + .into_filelike(), + ); + Tester::from_socket( + std::net::TcpListener::bind("127.0.0.1:0") + .unwrap() + .into_socketlike(), + ); + Tester::from_socket( + std::net::TcpListener::bind("127.0.0.1:0") + .unwrap() + .into_socketlike() + .into_socketlike(), + ); + + Tester::from_into_file(std::fs::File::open("Cargo.toml").unwrap().into_filelike()); + Tester::from_into_socket( + std::net::TcpListener::bind("127.0.0.1:0") + .unwrap() + .into_socketlike(), + ); +} + +#[test] +fn test_as() { + let file = std::fs::File::open("Cargo.toml").unwrap(); + let borrow: BorrowedFilelike = file.as_filelike(); + let reborrow: BorrowedFilelike = borrow.as_filelike(); + let ref_reborrow: &BorrowedFilelike = &reborrow; + let borrow_ref_reborrow: BorrowedFilelike = ref_reborrow.as_filelike(); + let _ref_borrow_ref_reborrow: &BorrowedFilelike = &borrow_ref_reborrow; +} diff --git a/vendor/io-lifetimes/tests/assumptions.rs b/vendor/io-lifetimes/tests/assumptions.rs new file mode 100644 index 000000000..33094b653 --- /dev/null +++ b/vendor/io-lifetimes/tests/assumptions.rs @@ -0,0 +1,45 @@ +#![cfg_attr(target_os = "wasi", feature(wasi_ext))] + +#[cfg(any(not(windows), feature = "close"))] +use std::mem::size_of; + +#[cfg(unix)] +#[test] +fn test_assumptions() { + assert_eq!(size_of::<std::os::unix::io::RawFd>(), size_of::<i32>()); + assert_eq!( + size_of::<std::os::unix::io::RawFd>(), + size_of::<std::os::raw::c_int>() + ); +} + +#[cfg(target_os = "wasi")] +#[test] +fn test_assumptions() { + assert_eq!(size_of::<std::os::wasi::io::RawFd>(), size_of::<i32>()); + assert_eq!( + size_of::<std::os::wasi::io::RawFd>(), + size_of::<std::os::raw::c_int>() + ); +} + +#[cfg(all(windows, feature = "close"))] +#[test] +fn test_assumptions() { + assert_eq!( + size_of::<std::os::windows::io::RawSocket>(), + size_of::<windows_sys::Win32::Networking::WinSock::SOCKET>() + ); + assert_eq!( + size_of::<std::os::windows::io::RawHandle>(), + size_of::<windows_sys::Win32::Foundation::HANDLE>() + ); + assert_eq!( + windows_sys::Win32::Networking::WinSock::INVALID_SOCKET, + usize::MAX + ); + assert_ne!( + windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE, + std::ptr::null_mut() as std::os::windows::io::RawHandle as _ + ); +} diff --git a/vendor/io-lifetimes/tests/ffi.rs b/vendor/io-lifetimes/tests/ffi.rs new file mode 100644 index 000000000..af03efe05 --- /dev/null +++ b/vendor/io-lifetimes/tests/ffi.rs @@ -0,0 +1,80 @@ +#![cfg_attr(not(rustc_attrs), allow(unused_imports))] +#![cfg(feature = "close")] +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +#[cfg(any(unix, windows))] +use io_lifetimes::example_ffi::*; +#[cfg(windows)] +use io_lifetimes::{InvalidHandleError, OwnedHandle}; +#[cfg(windows)] +use std::{convert::TryInto, os::windows::io::RawHandle, ptr::null_mut}; +#[cfg(windows)] +use windows_sys::Win32::Storage::FileSystem::{ + FILE_ATTRIBUTE_NORMAL, FILE_GENERIC_READ, OPEN_EXISTING, +}; + +#[cfg(all(rustc_attrs, unix))] +#[test] +fn test_file_not_found() { + assert!(unsafe { + open( + "/dev/no/such/file\0".as_ptr() as *const _, + O_RDONLY | O_CLOEXEC, + ) + } + .is_none()); +} + +#[cfg(windows)] +#[test] +fn test_file_not_found() { + let handle: Result<OwnedHandle, InvalidHandleError> = unsafe { + CreateFileW( + [ + 'C' as u16, ':' as _, '/' as _, 'n' as _, 'o' as _, '/' as _, 's' as _, 'u' as _, + 'c' as _, 'h' as _, '/' as _, 'f' as _, 'i' as _, 'l' as _, 'e' as _, 0, + ] + .as_ptr(), + FILE_GENERIC_READ, + 0, + null_mut(), + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + null_mut() as RawHandle as HANDLE, + ) + } + .try_into(); + assert!(handle.is_err()); + assert_eq!( + std::io::Error::last_os_error().kind(), + std::io::ErrorKind::NotFound + ); +} + +#[cfg(all(rustc_attrs, unix))] +#[test] +fn test_file_found() { + assert!(unsafe { open("Cargo.toml\0".as_ptr() as *const _, O_RDONLY | O_CLOEXEC) }.is_some()); +} + +#[cfg(windows)] +#[test] +fn test_file_found() { + let handle: Result<OwnedHandle, InvalidHandleError> = unsafe { + CreateFileW( + [ + 'C' as u16, 'a' as _, 'r' as _, 'g' as _, 'o' as _, '.' as _, 't' as _, 'o' as _, + 'm' as _, 'l' as _, 0, + ] + .as_ptr(), + FILE_GENERIC_READ, + 0, + null_mut(), + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + null_mut() as RawHandle as HANDLE, + ) + } + .try_into(); + assert!(handle.is_ok()); +} diff --git a/vendor/io-lifetimes/tests/niche-optimizations.rs b/vendor/io-lifetimes/tests/niche-optimizations.rs new file mode 100644 index 000000000..89316d559 --- /dev/null +++ b/vendor/io-lifetimes/tests/niche-optimizations.rs @@ -0,0 +1,71 @@ +#![cfg_attr(not(rustc_attrs), allow(unused_imports))] +#![cfg_attr(target_os = "wasi", feature(wasi_ext))] +#![cfg_attr(io_lifetimes_use_std, feature(io_safety))] + +use std::mem::size_of; + +#[cfg(any(unix, target_os = "wasi"))] +use io_lifetimes::{BorrowedFd, OwnedFd}; +#[cfg(windows)] +use io_lifetimes::{BorrowedSocket, OwnedSocket}; + +#[cfg(unix)] +use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{FromRawSocket, IntoRawSocket, RawFd}; +#[cfg(windows)] +use std::os::windows::io::{FromRawSocket, IntoRawSocket, RawSocket}; + +#[cfg(all(rustc_attrs, any(unix, target_os = "wasi")))] +#[test] +fn test_niche_optimizations() { + assert_eq!(size_of::<Option<OwnedFd>>(), size_of::<RawFd>()); + assert_eq!(size_of::<Option<BorrowedFd<'static>>>(), size_of::<RawFd>()); + unsafe { + assert_eq!(OwnedFd::from_raw_fd(RawFd::MIN).into_raw_fd(), RawFd::MIN); + assert_eq!(OwnedFd::from_raw_fd(RawFd::MAX).into_raw_fd(), RawFd::MAX); + assert_eq!( + Some(OwnedFd::from_raw_fd(RawFd::MIN)) + .unwrap() + .into_raw_fd(), + RawFd::MIN + ); + assert_eq!( + Some(OwnedFd::from_raw_fd(RawFd::MAX)) + .unwrap() + .into_raw_fd(), + RawFd::MAX + ); + } +} + +#[cfg(all(rustc_attrs, windows))] +#[test] +fn test_niche_optimizations_socket() { + assert_eq!(size_of::<Option<OwnedSocket>>(), size_of::<RawSocket>()); + assert_eq!( + size_of::<Option<BorrowedSocket<'static>>>(), + size_of::<RawSocket>(), + ); + unsafe { + #[cfg(target_pointer_width = "32")] + let (min, max) = (i32::MIN as u32, i32::MAX as u32); + #[cfg(target_pointer_width = "64")] + let (min, max) = (i64::MIN as u64, i64::MAX as u64); + + assert_eq!(OwnedSocket::from_raw_socket(min).into_raw_socket(), min); + assert_eq!(OwnedSocket::from_raw_socket(max).into_raw_socket(), max); + assert_eq!( + Some(OwnedSocket::from_raw_socket(min)) + .unwrap() + .into_raw_socket(), + min + ); + assert_eq!( + Some(OwnedSocket::from_raw_socket(max)) + .unwrap() + .into_raw_socket(), + max + ); + } +} |