io-lifetimes-2.0.3/.cargo_vcs_info.json0000644000000001360000000000100134240ustar { "git": { "sha1": "893a39ff6d84dc7d5fa9a03e26f8605cbeaea2ee" }, "path_in_vcs": "" }io-lifetimes-2.0.3/CODE_OF_CONDUCT.md000064400000000000000000000066521046102023000150240ustar 00000000000000# 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/ io-lifetimes-2.0.3/COPYRIGHT000064400000000000000000000015551046102023000135150ustar 00000000000000Short 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 or - the Apache License, Version 2.0 or , - or the MIT license or , at your option. io-lifetimes-2.0.3/Cargo.lock0000644000000614620000000000100114100ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "addr2line" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] [[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "async-channel" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", "event-listener 2.5.3", "futures-core", ] [[package]] name = "async-channel" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" dependencies = [ "concurrent-queue", "event-listener 4.0.0", "event-listener-strategy", "futures-core", "pin-project-lite", ] [[package]] name = "async-executor" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" dependencies = [ "async-lock 3.1.2", "async-task", "concurrent-queue", "fastrand 2.0.1", "futures-lite 2.0.1", "slab", ] [[package]] name = "async-global-executor" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4353121d5644cdf2beb5726ab752e79a8db1ebb52031770ec47db31d245526" dependencies = [ "async-channel 2.1.1", "async-executor", "async-io 2.2.1", "async-lock 3.1.2", "blocking", "futures-lite 2.0.1", "once_cell", ] [[package]] name = "async-io" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" dependencies = [ "async-lock 2.8.0", "autocfg", "cfg-if", "concurrent-queue", "futures-lite 1.13.0", "log", "parking", "polling 2.8.0", "rustix 0.37.27", "slab", "socket2 0.4.10", "waker-fn", ] [[package]] name = "async-io" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6d3b15875ba253d1110c740755e246537483f152fa334f91abd7fe84c88b3ff" dependencies = [ "async-lock 3.1.2", "cfg-if", "concurrent-queue", "futures-io", "futures-lite 2.0.1", "parking", "polling 3.3.1", "rustix 0.38.26", "slab", "tracing", "windows-sys 0.52.0", ] [[package]] name = "async-lock" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ "event-listener 2.5.3", ] [[package]] name = "async-lock" version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dea8b3453dd7cc96711834b75400d671b73e3656975fa68d9f277163b7f7e316" dependencies = [ "event-listener 4.0.0", "event-listener-strategy", "pin-project-lite", ] [[package]] name = "async-std" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" dependencies = [ "async-channel 1.9.0", "async-global-executor", "async-io 1.13.0", "async-lock 2.8.0", "crossbeam-utils", "futures-channel", "futures-core", "futures-io", "futures-lite 1.13.0", "gloo-timers", "kv-log-macro", "log", "memchr", "once_cell", "pin-project-lite", "pin-utils", "slab", "wasm-bindgen-futures", ] [[package]] name = "async-task" version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" [[package]] name = "atomic-waker" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", ] [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "blocking" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ "async-channel 2.1.1", "async-lock 3.1.2", "async-task", "fastrand 2.0.1", "futures-io", "futures-lite 2.0.1", "piper", "tracing", ] [[package]] name = "bumpalo" version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] [[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 = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if", ] [[package]] name = "errno" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", "windows-sys 0.52.0", ] [[package]] name = "event-listener" version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "770d968249b5d99410d61f5bf89057f3199a077a04d087092f58e7d10692baae" dependencies = [ "concurrent-queue", "parking", "pin-project-lite", ] [[package]] name = "event-listener-strategy" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ "event-listener 4.0.0", "pin-project-lite", ] [[package]] name = "fastrand" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] [[package]] name = "fastrand" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "futures-channel" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", ] [[package]] name = "futures-core" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-io" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ "fastrand 1.9.0", "futures-core", "futures-io", "memchr", "parking", "pin-project-lite", "waker-fn", ] [[package]] name = "futures-lite" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" dependencies = [ "fastrand 2.0.1", "futures-core", "futures-io", "memchr", "parking", "pin-project-lite", ] [[package]] name = "gimli" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "gloo-timers" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" dependencies = [ "futures-channel", "futures-core", "js-sys", "wasm-bindgen", ] [[package]] name = "hermit-abi" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[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 = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi", "libc", "windows-sys 0.48.0", ] [[package]] name = "io-lifetimes" version = "2.0.3" dependencies = [ "async-std", "hermit-abi", "libc", "mio", "os_pipe", "socket2 0.5.5", "tokio", "windows-sys 0.52.0", ] [[package]] name = "js-sys" version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" 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 = "libc" version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linux-raw-sys" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "log" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" dependencies = [ "value-bag", ] [[package]] name = "memchr" version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "miniz_oxide" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] [[package]] name = "mio" version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", "wasi", "windows-sys 0.48.0", ] [[package]] name = "object" version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "os_pipe" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177" dependencies = [ "libc", "windows-sys 0.48.0", ] [[package]] name = "parking" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "pin-project-lite" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "piper" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" dependencies = [ "atomic-waker", "fastrand 2.0.1", "futures-io", ] [[package]] name = "polling" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" dependencies = [ "autocfg", "bitflags 1.3.2", "cfg-if", "concurrent-queue", "libc", "log", "pin-project-lite", "windows-sys 0.48.0", ] [[package]] name = "polling" version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf63fa624ab313c11656b4cda960bfc46c410187ad493c41f6ba2d8c1e991c9e" dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", "rustix 0.38.26", "tracing", "windows-sys 0.52.0", ] [[package]] name = "proc-macro2" version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] [[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" version = "0.37.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", "io-lifetimes 1.0.11", "libc", "linux-raw-sys 0.3.8", "windows-sys 0.48.0", ] [[package]] name = "rustix" version = "0.38.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys 0.4.12", "windows-sys 0.52.0", ] [[package]] name = "signal-hook-registry" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] [[package]] name = "slab" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "socket2" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", ] [[package]] name = "socket2" version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys 0.48.0", ] [[package]] name = "syn" version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tokio" version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ "backtrace", "bytes", "libc", "mio", "pin-project-lite", "signal-hook-registry", "socket2 0.5.5", "windows-sys 0.48.0", ] [[package]] name = "tracing" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "value-bag" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a72e1902dde2bd6441347de2b70b7f5d59bf157c6c62f0c44572607a1d55bbe" [[package]] name = "waker-fn" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" [[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.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" dependencies = [ "cfg-if", "js-sys", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "web-sys" version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", ] [[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.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets 0.48.5", ] [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets 0.52.0", ] [[package]] name = "windows-targets" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm 0.48.5", "windows_aarch64_msvc 0.48.5", "windows_i686_gnu 0.48.5", "windows_i686_msvc 0.48.5", "windows_x86_64_gnu 0.48.5", "windows_x86_64_gnullvm 0.48.5", "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ "windows_aarch64_gnullvm 0.52.0", "windows_aarch64_msvc 0.52.0", "windows_i686_gnu 0.52.0", "windows_i686_msvc 0.52.0", "windows_x86_64_gnu 0.52.0", "windows_x86_64_gnullvm 0.52.0", "windows_x86_64_msvc 0.52.0", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" io-lifetimes-2.0.3/Cargo.toml0000644000000042660000000000100114320ustar # 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 = "2021" rust-version = "1.63" name = "io-lifetimes" version = "2.0.3" authors = ["Dan Gohman "] include = [ "src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md", ] description = "A low-level I/O ownership and borrowing library" readme = "README.md" 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" [package.metadata.docs.rs] features = ["close"] rustdoc-args = [ "--cfg", "doc_cfg", ] [dependencies] [features] close = [ "libc", "hermit-abi", "windows-sys", ] default = [] [target."cfg(not(target_os = \"wasi\"))".dependencies.async-std] version = "1.12.0" optional = true [target."cfg(not(target_os = \"wasi\"))".dependencies.mio] version = "0.8.0" features = [ "net", "os-ext", ] optional = true [target."cfg(not(target_os = \"wasi\"))".dependencies.os_pipe] version = "1.0.0" features = ["io_safety"] optional = true [target."cfg(not(target_os = \"wasi\"))".dependencies.socket2] version = "0.5.0" optional = true [target."cfg(not(target_os = \"wasi\"))".dependencies.tokio] version = "1.6.0" features = [ "io-std", "fs", "net", "process", ] optional = true [target."cfg(not(windows))".dependencies.libc] version = "0.2.96" optional = true [target."cfg(target_os = \"hermit\")".dependencies.hermit-abi] version = "0.3" optional = true [target."cfg(windows)".dependencies.windows-sys] version = "0.52.0" features = [ "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_Networking_WinSock", "Win32_Security", "Win32_System_IO", ] optional = true io-lifetimes-2.0.3/Cargo.toml.orig000064400000000000000000000037151046102023000151110ustar 00000000000000[package] name = "io-lifetimes" version = "2.0.3" description = "A low-level I/O ownership and borrowing library" authors = ["Dan Gohman "] license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT" keywords = ["api", "io"] categories = ["os", "rust-patterns"] edition = "2021" repository = "https://github.com/sunfishcode/io-lifetimes" include = ["src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] rust-version = "1.63" [dependencies] # io-lifetimes only depends on libc/windows-sys for the ability to close # and duplicate fds/handles/sockets. The following are just optional # dependencies to add foreign-type impls for the traits. [target.'cfg(not(target_os = "wasi"))'.dependencies] # Optionally depend on os_pipe to implement traits for its types for now. os_pipe = { version = "1.0.0", features = ["io_safety"], optional = true } # Optionally depend on async-std just to provide impls for its types. async-std = { version = "1.12.0", optional = true } # Optionally depend on tokio to implement traits for its types. tokio = { version = "1.6.0", features = ["io-std", "fs", "net", "process"], optional = true } # Optionally depend on socket2 to implement traits for its types. socket2 = { version = "0.5.0", optional = true } # Optionally depend on mio to implement traits for its types. mio = { version = "0.8.0", features = ["net", "os-ext"], optional = true } [target.'cfg(target_os = "hermit")'.dependencies] hermit-abi = { version = "0.3", optional = true } [target.'cfg(not(windows))'.dependencies] libc = { version = "0.2.96", optional = true } [target.'cfg(windows)'.dependencies.windows-sys] version = "0.52.0" optional = true features = [ "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_Networking_WinSock", "Win32_Security", "Win32_System_IO", ] [package.metadata.docs.rs] features = ["close"] rustdoc-args = ["--cfg", "doc_cfg"] [features] default = [] close = ["libc", "hermit-abi", "windows-sys"] io-lifetimes-2.0.3/LICENSE-APACHE000064400000000000000000000251371046102023000141500ustar 00000000000000 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. io-lifetimes-2.0.3/LICENSE-Apache-2.0_WITH_LLVM-exception000064400000000000000000000277231046102023000203710ustar 00000000000000 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. io-lifetimes-2.0.3/LICENSE-MIT000064400000000000000000000017771046102023000136640ustar 00000000000000Permission 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. io-lifetimes-2.0.3/ORG_CODE_OF_CONDUCT.md000064400000000000000000000160721046102023000155300ustar 00000000000000# 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. io-lifetimes-2.0.3/README.md000064400000000000000000000177741046102023000135130ustar 00000000000000

io-lifetimes

A low-level I/O ownership and borrowing library

Github Actions CI Status crates.io page docs.rs docs

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`. 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` and `Option` are FFI-safe (on Rust >= 1.63), 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; 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` as the return value of `open`, representing the fact that it can either succeed or fail. ## I/O Safety in Rust I/O Safety feature is stablized in Rust 1.63. With this version or later, io-lifetimes will use and re-export the standard-library types and traits. With older versions, io-lifetimes defines its own copy of these types and traits. 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]. [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 Rust >= 1.63), 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` (on Rust >= 1.63) 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. ## Minimum Supported Rust Version (MSRV) This crate currently works on the version of [Rust on Debian stable], which is currently Rust 1.63. This policy may change in the future, in minor version releases, so users using a fixed version of Rust should pin to a specific version of this crate. [`OwnedFd`]: https://doc.rust-lang.org/stable/std/os/fd/struct.OwnedFd.html [`BorrowedFd`]: https://doc.rust-lang.org/stable/std/os/fd/struct.BorrowedFd.html [RFC 3128]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md io-lifetimes-2.0.3/build.rs000064400000000000000000000051141046102023000136620ustar 00000000000000use std::env::var; use std::io::Write; fn main() { let target_os = var("CARGO_CFG_TARGET_OS").unwrap(); // Work around // . if target_os == "wasi" { use_feature_or_nothing("wasi_ext"); } // 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 { can_compile(format!( "#![allow(stable_features)]\n#![feature({})]", feature )) } /// Test whether the rustc at `var("RUSTC")` can compile the given code. fn can_compile>(test: T) -> bool { use std::process::Stdio; let out_dir = var("OUT_DIR").unwrap(); let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); // Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, // as documented [here]. // [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads let wrapper = var("RUSTC_WRAPPER") .ok() .and_then(|w| if w.is_empty() { None } else { Some(w) }); let mut cmd = if let Some(wrapper) = wrapper { let mut cmd = std::process::Command::new(wrapper); // The wrapper's first argument is supposed to be the path to rustc. cmd.arg(rustc); cmd } else { std::process::Command::new(rustc) }; cmd.arg("--crate-type=rlib") // Don't require `main`. .arg("--emit=metadata") // Do as little as possible but still parse. .arg("--target") .arg(target) .arg("--out-dir") .arg(out_dir); // Put the output somewhere inconsequential. // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") { if !rustflags.is_empty() { for arg in rustflags.split('\x1f') { cmd.arg(arg); } } } let mut child = cmd .arg("-") // Read from stdin. .stdin(Stdio::piped()) // Stdin is a pipe. .stderr(Stdio::null()) // Errors from feature detection aren't interesting and can be confusing. .spawn() .unwrap(); writeln!(child.stdin.take().unwrap(), "{}", test.as_ref()).unwrap(); child.wait().unwrap().success() } io-lifetimes-2.0.3/src/example_ffi.rs000064400000000000000000000050001046102023000156230ustar 00000000000000//! This is just a sample of what FFI using this crate can look like. #![allow(missing_docs)] #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] use crate::{BorrowedFd, OwnedFd}; #[cfg(windows)] use crate::{BorrowedHandle, HandleOrInvalid}; #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] 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_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(any(unix, target_os = "wasi", target_os = "hermit"))] extern "C" { pub fn open(pathname: *const c_char, flags: c_int, ...) -> Option; } #[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: u32, 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, }, }; io-lifetimes-2.0.3/src/lib.rs000064400000000000000000000101371046102023000141210ustar 00000000000000//! 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)] // Work around . #![cfg_attr(all(wasi_ext, target_os = "wasi"), feature(wasi_ext))] // Currently supported platforms. #![cfg(any(unix, windows, target_os = "wasi", target_os = "hermit"))] #![cfg_attr(doc_cfg, feature(doc_cfg))] mod portability; mod traits; #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] #[allow(deprecated)] pub use traits::{FromFd, IntoFd}; #[cfg(windows)] #[allow(deprecated)] pub use traits::{FromHandle, FromSocket, IntoHandle, IntoSocket}; #[cfg(target_os = "hermit")] pub use std::os::hermit::io::{AsFd, BorrowedFd, OwnedFd}; #[cfg(unix)] pub use std::os::unix::io::{AsFd, BorrowedFd, OwnedFd}; #[cfg(target_os = "wasi")] pub use std::os::wasi::io::{AsFd, BorrowedFd, OwnedFd}; #[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(any(unix, target_os = "wasi", target_os = "hermit"))] #[allow(deprecated)] impl> FromFd for T { #[inline] fn from_fd(owned_fd: OwnedFd) -> Self { owned_fd.into() } } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] #[allow(deprecated)] impl IntoFd for T where OwnedFd: From, { #[inline] fn into_fd(self) -> OwnedFd { self.into() } } #[cfg(windows)] #[allow(deprecated)] impl> FromHandle for T { #[inline] fn from_handle(owned_handle: OwnedHandle) -> Self { owned_handle.into() } } #[cfg(windows)] #[allow(deprecated)] impl IntoHandle for T where OwnedHandle: From, { #[inline] fn into_handle(self) -> OwnedHandle { self.into() } } #[cfg(windows)] #[allow(deprecated)] impl> FromSocket for T { #[inline] fn from_socket(owned_socket: OwnedSocket) -> Self { owned_socket.into() } } #[cfg(windows)] #[allow(deprecated)] impl IntoSocket for T where OwnedSocket: From, { #[inline] fn into_socket(self) -> OwnedSocket { self.into() } } pub use portability::{ AsFilelike, AsSocketlike, BorrowedFilelike, BorrowedSocketlike, FromFilelike, FromSocketlike, IntoFilelike, IntoSocketlike, OwnedFilelike, OwnedSocketlike, }; #[cfg(feature = "close")] #[cfg_attr(doc_cfg, doc(cfg(feature = "close")))] pub mod example_ffi; pub mod raw; pub mod views; io-lifetimes-2.0.3/src/portability.rs000064400000000000000000000422231046102023000157160ustar 00000000000000//! 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", target_os = "hermit"))] use crate::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use crate::{AsHandle, AsSocket, BorrowedHandle, BorrowedSocket, 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", target_os = "hermit"))] 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", target_os = "hermit"))] 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", target_os = "hermit"))] 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", target_os = "hermit"))] 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", target_os = "hermit"))] 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::(); /// (&*v).read(&mut buf).unwrap(); /// ``` /// /// [`File`]: std::fs::File /// [`Read`]: std::io::Read /// [`Write`]: std::io::Write fn as_filelike_view(&self) -> FilelikeView<'_, Target>; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl AsFilelike for T { #[inline] fn as_filelike(&self) -> BorrowedFilelike<'_> { self.as_fd() } #[inline] fn as_filelike_view(&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::(); /// (&*v).read(&mut buf).unwrap(); /// ``` /// /// [`File`]: std::fs::File /// [`Read`]: std::io::Read /// [`Write`]: std::io::Write fn as_filelike_view(&self) -> FilelikeView<'_, Target>; } #[cfg(windows)] impl AsFilelike for T { #[inline] fn as_filelike(&self) -> BorrowedFilelike<'_> { self.as_handle() } #[inline] fn as_filelike_view(&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", target_os = "hermit"))] 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::(); /// (&*v).read(&mut buf).unwrap(); /// ``` /// /// [`TcpStream`]: std::net::TcpStream /// [`Read`]: std::io::Read /// [`Write`]: std::io::Write fn as_socketlike_view(&self) -> SocketlikeView<'_, Target>; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl AsSocketlike for T { #[inline] fn as_socketlike(&self) -> BorrowedSocketlike<'_> { self.as_fd() } #[inline] fn as_socketlike_view(&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::(); /// (&*v).read(&mut buf).unwrap(); /// ``` /// /// [`TcpStream`]: std::net::TcpStream fn as_socketlike_view(&self) -> SocketlikeView<'_, Target>; } #[cfg(windows)] impl AsSocketlike for T { #[inline] fn as_socketlike(&self) -> BorrowedSocketlike<'_> { self.as_socket() } #[inline] fn as_socketlike_view(&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 [`Into`] and /// Windows' `Into`. #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] pub trait IntoFilelike: Into { /// 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", target_os = "hermit"))] impl> IntoFilelike for T { #[inline] fn into_filelike(self) -> OwnedFilelike { self.into() } } /// 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 `Into` and /// Windows' [`Into`]. #[cfg(windows)] pub trait IntoFilelike: Into { /// Consumes this object, returning the underlying filelike object. fn into_filelike(self) -> OwnedFilelike; } #[cfg(windows)] impl> IntoFilelike for T { #[inline] fn into_filelike(self) -> OwnedFilelike { self.into() } } /// 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 [`Into`] and /// Windows' `Into`. #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] pub trait IntoSocketlike: Into { /// Consumes this object, returning the underlying socketlike object. fn into_socketlike(self) -> OwnedSocketlike; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl> IntoSocketlike for T { #[inline] fn into_socketlike(self) -> OwnedSocketlike { self.into() } } /// 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 `Into` and /// Windows' [`Into`]. #[cfg(windows)] pub trait IntoSocketlike: Into { /// 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> IntoSocketlike for T { #[inline] fn into_socketlike(self) -> OwnedSocketlike { self.into() } } /// A portable trait to express the ability to construct an object from a /// filelike object. /// /// This is a portability abstraction over Unix-like [`From`] and /// Windows' `From`. It also provides the `from_into_filelike` /// convenience function providing simplified from+into conversions. #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] pub trait FromFilelike: From { /// 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: Owned) -> Self; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl> FromFilelike for T { #[inline] fn from_filelike(owned: OwnedFilelike) -> Self { Self::from(owned) } #[inline] fn from_into_filelike(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 `From` and /// Windows' [`From`]. It also provides the `from_into_filelike` /// convenience function providing simplified from+into conversions. #[cfg(windows)] pub trait FromFilelike: From { /// 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: Owned) -> Self; } #[cfg(windows)] impl> FromFilelike for T { #[inline] fn from_filelike(owned: OwnedFilelike) -> Self { Self::from(owned) } #[inline] fn from_into_filelike(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 [`From`] and /// Windows' `From` It also provides the /// `from_into_socketlike` convenience function providing simplified from+into /// conversions. #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] pub trait FromSocketlike: From { /// 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: Owned) -> Self; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl> FromSocketlike for T { #[inline] fn from_socketlike(owned: OwnedSocketlike) -> Self { Self::from(owned) } #[inline] fn from_into_socketlike(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 `From` and /// Windows' [`From`]. It also provides the `from_into_socketlike` /// convenience function providing simplified from+into conversions. #[cfg(windows)] pub trait FromSocketlike: From { /// 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: Owned) -> Self; } #[cfg(windows)] impl> FromSocketlike for T { #[inline] fn from_socketlike(owned: OwnedSocketlike) -> Self { Self::from(owned) } #[inline] fn from_into_socketlike(owned: Owned) -> Self { Self::from_socketlike(owned.into_socketlike()) } } io-lifetimes-2.0.3/src/raw.rs000064400000000000000000000172011046102023000141430ustar 00000000000000//! 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(target_os = "hermit")] use std::os::hermit::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[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", target_os = "hermit"))] 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", target_os = "hermit"))] 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", target_os = "hermit"))] pub trait AsRawFilelike: AsRawFd { /// Returns the raw value. fn as_raw_filelike(&self) -> RawFilelike; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl 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 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", target_os = "hermit"))] pub trait AsRawSocketlike: AsRawFd { /// Returns the raw value. fn as_raw_socketlike(&self) -> RawSocketlike; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl 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 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", target_os = "hermit"))] pub trait IntoRawFilelike: IntoRawFd { /// Returns the raw value. fn into_raw_filelike(self) -> RawFilelike; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl 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 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", target_os = "hermit"))] pub trait IntoRawSocketlike: IntoRawFd { /// Returns the raw value. fn into_raw_socketlike(self) -> RawSocketlike; } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] impl 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 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", target_os = "hermit"))] 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/fd/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", target_os = "hermit"))] impl 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 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", target_os = "hermit"))] 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/fd/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", target_os = "hermit"))] impl 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 FromRawSocketlike for T { #[inline] unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self { Self::from_raw_socket(raw) } } io-lifetimes-2.0.3/src/traits.rs000064400000000000000000000121251046102023000146600ustar 00000000000000#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] use crate::OwnedFd; #[cfg(windows)] use crate::{OwnedHandle, OwnedSocket}; /// A trait to express the ability to consume an object and acquire ownership /// of its file descriptor. #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] #[deprecated( since = "1.0.0", note = "`IntoFd` is replaced by `From<...> for OwnedFd` or `Into`" )] pub trait IntoFd { /// Consumes this object, returning the underlying file descriptor. /// /// # Example /// /// ```rust,no_run /// 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)] #[deprecated( since = "1.0.0", note = "`IntoHandle` is replaced by `From<...> for OwnedHandle` or `Into`" )] pub trait IntoHandle { /// Consumes this object, returning the underlying handle. /// /// # Example /// /// ```rust,no_run /// 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)] #[deprecated( since = "1.0.0", note = "`IntoSocket` is replaced by `From<...> for OwnedSocket` or `Into`" )] 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", target_os = "hermit"))] pub trait FromFd { /// Constructs a new instance of `Self` from the given file descriptor. /// /// # Example /// /// ```rust,no_run /// 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>(()) /// ``` #[deprecated( since = "1.0.0", note = "`FromFd::from_fd` is replaced by `From::from`" )] 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 /// 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>(into_owned: Owned) -> Self where Self: Sized + From, { Self::from(into_owned.into()) } } /// 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 /// 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>(()) /// ``` #[deprecated( since = "1.0.0", note = "`FromHandle::from_handle` is replaced by `From::from`" )] fn from_handle(owned: OwnedHandle) -> Self; /// Constructs a new instance of `Self` from the given handle converted /// from `into_owned`. /// /// # Example /// /// ```rust,no_run /// 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>(into_owned: Owned) -> Self where Self: Sized + From, { Self::from(into_owned.into()) } } /// 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. #[deprecated( since = "1.0.0", note = "`FromSocket::from_socket` is replaced by `From::from`" )] 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>(into_owned: Owned) -> Self where Self: Sized + From, { Self::from(into_owned.into()) } } io-lifetimes-2.0.3/src/views.rs000064400000000000000000000236761046102023000145240ustar 00000000000000//! 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, }; #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] use crate::OwnedFd; use crate::{ AsFilelike, AsSocketlike, FromFilelike, FromSocketlike, IntoFilelike, IntoSocketlike, OwnedFilelike, OwnedSocketlike, }; #[cfg(windows)] use crate::{OwnedHandle, OwnedSocket}; 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, /// `FilelikeViewType` implementors guarantee that their `Into` /// returns the same fd as their `From` 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, /// `SocketlikeViewType` implementors guarantee that their `Into` /// returns the same fd as their `From` 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 FilelikeView<'_, Target> { /// Construct a temporary `Target` and wrap it in a `FilelikeView` object. #[inline] pub(crate) fn new(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 SocketlikeView<'_, Target> { /// Construct a temporary `Target` and wrap it in a `SocketlikeView` /// object. #[inline] pub(crate) fn new(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 Deref for FilelikeView<'_, Target> { type Target = Target; #[inline] fn deref(&self) -> &Self::Target { &self.target } } impl Deref for SocketlikeView<'_, Target> { type Target = Target; #[inline] fn deref(&self) -> &Self::Target { &self.target } } impl 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 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 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 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() } } #[cfg(any(unix, target_os = "wasi", target_os = "hermit"))] 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 {} #[cfg(not(any(target_os = "wasi", target_os = "hermit")))] #[cfg(feature = "os_pipe")] unsafe impl FilelikeViewType for os_pipe::PipeWriter {} #[cfg(not(any(target_os = "wasi", target_os = "hermit")))] #[cfg(feature = "os_pipe")] unsafe impl FilelikeViewType for os_pipe::PipeReader {} #[cfg(not(any(target_os = "wasi", target_os = "hermit")))] #[cfg(feature = "socket2")] unsafe impl SocketlikeViewType for socket2::Socket {} #[cfg(not(any(target_os = "wasi", target_os = "hermit")))] #[cfg(feature = "async_std")] unsafe impl SocketlikeViewType for async_std::net::TcpStream {} #[cfg(not(any(target_os = "wasi", target_os = "hermit")))] #[cfg(feature = "async_std")] unsafe impl SocketlikeViewType for async_std::net::TcpListener {} #[cfg(not(any(target_os = "wasi", target_os = "hermit")))] #[cfg(feature = "async_std")] unsafe impl SocketlikeViewType for async_std::net::UdpSocket {} #[cfg(unix)] #[cfg(feature = "async_std")] unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixStream {} #[cfg(unix)] #[cfg(feature = "async_std")] unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixListener {} #[cfg(unix)] #[cfg(feature = "async_std")] unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixDatagram {} #[cfg(feature = "mio")] unsafe impl SocketlikeViewType for mio::net::TcpStream {} #[cfg(feature = "mio")] unsafe impl SocketlikeViewType for mio::net::TcpListener {} #[cfg(feature = "mio")] unsafe impl SocketlikeViewType for mio::net::UdpSocket {} #[cfg(unix)] #[cfg(feature = "mio")] unsafe impl SocketlikeViewType for mio::net::UnixDatagram {} #[cfg(unix)] #[cfg(feature = "mio")] unsafe impl SocketlikeViewType for mio::net::UnixListener {} #[cfg(unix)] #[cfg(feature = "mio")] unsafe impl SocketlikeViewType for mio::net::UnixStream {} #[cfg(unix)] #[cfg(feature = "mio")] unsafe impl FilelikeViewType for mio::unix::pipe::Receiver {} #[cfg(unix)] #[cfg(feature = "mio")] unsafe impl FilelikeViewType for mio::unix::pipe::Sender {}