mirror of
https://gitee.com/openharmony/third_party_rust_io-lifetimes
synced 2024-11-23 07:10:21 +00:00
Rename to io-lifetimes, add codes of conduct.
This commit is contained in:
parent
b084153e81
commit
d0a01d1e4f
49
CODE_OF_CONDUCT.md
Normal file
49
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
*Note*: this Code of Conduct pertains to individuals' behavior. Please also see the [Organizational Code of Conduct][OCoC].
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Bytecode Alliance CoC team at [report@bytecodealliance.org](mailto:report@bytecodealliance.org). The CoC team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The CoC team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the Bytecode Alliance's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[OCoC]: https://github.com/sunfishcode/io-lifetimes/blob/main/ORG_CODE_OF_CONDUCT.md
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[version]: https://www.contributor-covenant.org/version/1/4/
|
@ -1,19 +1,19 @@
|
||||
Short version for non-lawyers:
|
||||
|
||||
`io-experiment` is triple-licensed under Apache 2.0 with the LLVM Exception,
|
||||
`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-experiment` project are retained by their contributors.
|
||||
No copyright assignment is required to contribute to the `io-experiment`
|
||||
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-experiment`
|
||||
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
|
||||
|
@ -1,13 +1,13 @@
|
||||
[package]
|
||||
name = "io-experiment"
|
||||
name = "io-lifetimes"
|
||||
version = "0.0.0"
|
||||
description = "An experimental low-level I/O library"
|
||||
description = "A low-level I/O ownership and borrowing library"
|
||||
authors = ["Dan Gohman <dev@sunfishcode.online>"]
|
||||
license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
|
||||
keywords = ["api", "io"]
|
||||
categories = ["os", "rust-patterns"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/sunfishcode/io-experiment"
|
||||
repository = "https://github.com/sunfishcode/io-lifetimes"
|
||||
exclude = ["/.github"]
|
||||
|
||||
[build-dependencies]
|
||||
|
143
ORG_CODE_OF_CONDUCT.md
Normal file
143
ORG_CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,143 @@
|
||||
# Bytecode Alliance Organizational Code of Conduct (OCoC)
|
||||
|
||||
*Note*: this Code of Conduct pertains to organizations' behavior. Please also see the [Individual Code of Conduct](CODE_OF_CONDUCT.md).
|
||||
|
||||
## Preamble
|
||||
|
||||
The Bytecode Alliance (BA) welcomes involvement from organizations,
|
||||
including commercial organizations. This document is an
|
||||
*organizational* code of conduct, intended particularly to provide
|
||||
guidance to commercial organizations. It is distinct from the
|
||||
[Individual Code of Conduct (ICoC)](CODE_OF_CONDUCT.md), and does not
|
||||
replace the ICoC. This OCoC applies to any group of people acting in
|
||||
concert as a BA member or as a participant in BA activities, whether
|
||||
or not that group is formally incorporated in some jurisdiction.
|
||||
|
||||
The code of conduct described below is not a set of rigid rules, and
|
||||
we did not write it to encompass every conceivable scenario that might
|
||||
arise. For example, it is theoretically possible there would be times
|
||||
when asserting patents is in the best interest of the BA community as
|
||||
a whole. In such instances, consult with the BA, strive for
|
||||
consensus, and interpret these rules with an intent that is generous
|
||||
to the community the BA serves.
|
||||
|
||||
While we may revise these guidelines from time to time based on
|
||||
real-world experience, overall they are based on a simple principle:
|
||||
|
||||
*Bytecode Alliance members should observe the distinction between
|
||||
public community functions and private functions — especially
|
||||
commercial ones — and should ensure that the latter support, or at
|
||||
least do not harm, the former.*
|
||||
|
||||
## Guidelines
|
||||
|
||||
* **Do not cause confusion about Wasm standards or interoperability.**
|
||||
|
||||
Having an interoperable WebAssembly core is a high priority for
|
||||
the BA, and members should strive to preserve that core. It is fine
|
||||
to develop additional non-standard features or APIs, but they
|
||||
should always be clearly distinguished from the core interoperable
|
||||
Wasm.
|
||||
|
||||
Treat the WebAssembly name and any BA-associated names with
|
||||
respect, and follow BA trademark and branding guidelines. If you
|
||||
distribute a customized version of software originally produced by
|
||||
the BA, or if you build a product or service using BA-derived
|
||||
software, use names that clearly distinguish your work from the
|
||||
original. (You should still provide proper attribution to the
|
||||
original, of course, wherever such attribution would normally be
|
||||
given.)
|
||||
|
||||
Further, do not use the WebAssembly name or BA-associated names in
|
||||
other public namespaces in ways that could cause confusion, e.g.,
|
||||
in company names, names of commercial service offerings, domain
|
||||
names, publicly-visible social media accounts or online service
|
||||
accounts, etc. It may sometimes be reasonable, however, to
|
||||
register such a name in a new namespace and then immediately donate
|
||||
control of that account to the BA, because that would help the project
|
||||
maintain its identity.
|
||||
|
||||
For further guidance, see the BA Trademark and Branding Policy
|
||||
[TODO: create policy, then insert link].
|
||||
|
||||
* **Do not restrict contributors.** If your company requires
|
||||
employees or contractors to sign non-compete agreements, those
|
||||
agreements must not prevent people from participating in the BA or
|
||||
contributing to related projects.
|
||||
|
||||
This does not mean that all non-compete agreements are incompatible
|
||||
with this code of conduct. For example, a company may restrict an
|
||||
employee's ability to solicit the company's customers. However, an
|
||||
agreement must not block any form of technical or social
|
||||
participation in BA activities, including but not limited to the
|
||||
implementation of particular features.
|
||||
|
||||
The accumulation of experience and expertise in individual persons,
|
||||
who are ultimately free to direct their energy and attention as
|
||||
they decide, is one of the most important drivers of progress in
|
||||
open source projects. A company that limits this freedom may hinder
|
||||
the success of the BA's efforts.
|
||||
|
||||
* **Do not use patents as offensive weapons.** If any BA participant
|
||||
prevents the adoption or development of BA technologies by
|
||||
asserting its patents, that undermines the purpose of the
|
||||
coalition. The collaboration fostered by the BA cannot include
|
||||
members who act to undermine its work.
|
||||
|
||||
* **Practice responsible disclosure** for security vulnerabilities.
|
||||
Use designated, non-public reporting channels to disclose technical
|
||||
vulnerabilities, and give the project a reasonable period to
|
||||
respond, remediate, and patch. [TODO: optionally include the
|
||||
security vulnerability reporting URL here.]
|
||||
|
||||
Vulnerability reporters may patch their company's own offerings, as
|
||||
long as that patching does not significantly delay the reporting of
|
||||
the vulnerability. Vulnerability information should never be used
|
||||
for unilateral commercial advantage. Vendors may legitimately
|
||||
compete on the speed and reliability with which they deploy
|
||||
security fixes, but withholding vulnerability information damages
|
||||
everyone in the long run by risking harm to the BA project's
|
||||
reputation and to the security of all users.
|
||||
|
||||
* **Respect the letter and spirit of open source practice.** While
|
||||
there is not space to list here all possible aspects of standard
|
||||
open source practice, some examples will help show what we mean:
|
||||
|
||||
* Abide by all applicable open source license terms. Do not engage
|
||||
in copyright violation or misattribution of any kind.
|
||||
|
||||
* Do not claim others' ideas or designs as your own.
|
||||
|
||||
* When others engage in publicly visible work (e.g., an upcoming
|
||||
demo that is coordinated in a public issue tracker), do not
|
||||
unilaterally announce early releases or early demonstrations of
|
||||
that work ahead of their schedule in order to secure private
|
||||
advantage (such as marketplace advantage) for yourself.
|
||||
|
||||
The BA reserves the right to determine what constitutes good open
|
||||
source practices and to take action as it deems appropriate to
|
||||
encourage, and if necessary enforce, such practices.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of organizational behavior in violation of the OCoC may
|
||||
be reported by contacting the Bytecode Alliance CoC team at
|
||||
[report@bytecodealliance.org](mailto:report@bytecodealliance.org). The
|
||||
CoC team will review and investigate all complaints, and will respond
|
||||
in a way that it deems appropriate to the circumstances. The CoC team
|
||||
is obligated to maintain confidentiality with regard to the reporter of
|
||||
an incident. Further details of specific enforcement policies may be
|
||||
posted separately.
|
||||
|
||||
When the BA deems an organization in violation of this OCoC, the BA
|
||||
will, at its sole discretion, determine what action to take. The BA
|
||||
will decide what type, degree, and duration of corrective action is
|
||||
needed, if any, before a violating organization can be considered for
|
||||
membership (if it was not already a member) or can have its membership
|
||||
reinstated (if it was a member and the BA canceled its membership due
|
||||
to the violation).
|
||||
|
||||
In practice, the BA's first approach will be to start a conversation,
|
||||
with punitive enforcement used only as a last resort. Violations
|
||||
often turn out to be unintentional and swiftly correctable with all
|
||||
parties acting in good faith.
|
50
README.md
50
README.md
@ -1,7 +1,13 @@
|
||||
This is an experiment, associated with [RFC 3128].
|
||||
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.
|
||||
|
||||
Some features require nightly Rust, as they depend on `rustc_attrs` to
|
||||
perform niche optimizations needed for FFI use cases.
|
||||
This is associated with [RFC 3128], the I/O Safety RFC, which proposes that
|
||||
this API be added to `std`, with the goal being to eventually replace `RawFd`
|
||||
etc. for most use cases.
|
||||
|
||||
Some features currently require nightly Rust, as they depend on `rustc_attrs`
|
||||
to perform niche optimizations needed for FFI use cases.
|
||||
|
||||
For a quick taste, check out the code examples:
|
||||
|
||||
@ -12,10 +18,10 @@ For a quick taste, check out the code examples:
|
||||
- [portable-views], demonstrating the convenience feature which allows one
|
||||
to temporarily "view" a file descriptor as any owning type such as `File`
|
||||
|
||||
[hello]: https://github.com/sunfishcode/io-experiment/blob/main/examples/hello.rs
|
||||
[easy-conversions]: https://github.com/sunfishcode/io-experiment/blob/main/examples/easy-conversions.rs
|
||||
[portable-views]: https://github.com/sunfishcode/io-experiment/blob/main/examples/portable-views.rs
|
||||
[provided example FFI bindings]: https://github.com/sunfishcode/io-experiment/blob/main/src/example_ffi.rs
|
||||
[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
|
||||
[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:
|
||||
@ -55,7 +61,7 @@ Here's the fun part. `BorrowedFd` and `OwnedFd` are `repr(transparent)` and
|
||||
hold `RawFd` values, and `Option<BorrowedFd>` and `Option<OwnedFd>` are
|
||||
FFI-safe (on nightly Rust), so they can all be used in FFI [directly]:
|
||||
|
||||
[directly]: https://github.com/sunfishcode/io-experiment/blob/main/src/example_ffi.rs
|
||||
[directly]: https://github.com/sunfishcode/io-lifetimes/blob/main/src/example_ffi.rs
|
||||
|
||||
```rust
|
||||
extern "C" {
|
||||
@ -83,56 +89,56 @@ There are several similar crates: [fd](https://crates.io/crates/fd),
|
||||
|
||||
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-experiment omits these features, leaving them to to be provided as separate
|
||||
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-experiment
|
||||
Most of these crates provide ways to duplicate a file descriptor. io-lifetimes
|
||||
currently treats this as another feature than 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-experiment's distinguishing features are its use of `repr(transparent)`
|
||||
io-lifetimes's distinguishing features are its use of `repr(transparent)`
|
||||
to support direct FFI usage, niche optimizations so `Option` can support direct
|
||||
FFI usafe as well (on nightly Rust), lifetime-aware `As*`/`Into*`/`From*`
|
||||
traits which leverage Rust's lifetime system and allow safe and checked
|
||||
`from_*` and `as_*`/`into_*` functions, and powerful convenience features
|
||||
enabled by its underlying safety.
|
||||
|
||||
io-experiment also has full Windows support, as well as Unix/Windows
|
||||
io-lifetimes also has full Windows support, as well as Unix/Windows
|
||||
portability abstractions, covering both file-like and socket-like types.
|
||||
|
||||
io-experiment's [`OwnedFd`] type is similar to
|
||||
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-experiment
|
||||
[`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-experiment's [`OwnedFd`] type is also similar to
|
||||
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-experiment's `OwnedFd` reserves the value -1, so it doesn't need to test for
|
||||
io-lifetimes's `OwnedFd` reserves the value -1, so it doesn't need to test for
|
||||
`-1` in its `Drop`, and `Option<OwnedFd>` is the same size as `OwnedFd` (on
|
||||
nightly Rust).
|
||||
|
||||
io-experiment's [`OwnedFd`] type is also similar to
|
||||
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-experiment doesn't implement `Clone`, because duplicating a file descriptor
|
||||
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-experiment's [`BorrowedFd`] is similar to
|
||||
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-experiment's convenience features are similar to those of
|
||||
[unsafe-io](https://crates.io/crates/unsafe-io), but io-experiment is built on
|
||||
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-experiment doesn't include unsafe-io's
|
||||
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.
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use io_experiment::FromFilelike;
|
||||
use io_lifetimes::FromFilelike;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read};
|
||||
use std::process::{Command, Stdio};
|
||||
|
@ -1,19 +1,19 @@
|
||||
#![cfg_attr(not(rustc_attrs), allow(unused_imports))]
|
||||
|
||||
use io_experiment::example_ffi::*;
|
||||
use io_lifetimes::example_ffi::*;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
|
||||
#[cfg(unix)]
|
||||
use io_experiment::{AsFd, FromFd, IntoFd, OwnedFd};
|
||||
use io_lifetimes::{AsFd, FromFd, IntoFd, OwnedFd};
|
||||
|
||||
#[cfg(windows)]
|
||||
use io_experiment::{AsHandle, FromHandle, IntoHandle, OwnedHandle};
|
||||
use io_lifetimes::{AsHandle, FromHandle, IntoHandle, OwnedHandle};
|
||||
#[cfg(windows)]
|
||||
use std::{convert::TryInto, ptr::null_mut};
|
||||
|
||||
/// A simple testcase that prints a few messages to the console, demonstrating
|
||||
/// the io-experiment API.
|
||||
/// the io-lifetimes API.
|
||||
#[cfg(all(rustc_attrs, unix))]
|
||||
fn main() -> io::Result<()> {
|
||||
let fd = unsafe {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use io_experiment::AsFilelike;
|
||||
use io_lifetimes::AsFilelike;
|
||||
use std::fs::File;
|
||||
use std::io::{self, stdout};
|
||||
|
||||
|
@ -104,7 +104,7 @@ pub trait AsFilelike: AsFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{AsFilelike, BorrowedFilelike};
|
||||
/// use io_lifetimes::{AsFilelike, BorrowedFilelike};
|
||||
///
|
||||
/// let mut f = File::open("foo.txt")?;
|
||||
/// let borrowed_filelike: BorrowedFilelike<'_> = f.as_filelike();
|
||||
@ -146,7 +146,7 @@ pub trait AsFilelike: AsHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{AsFilelike, BorrowedFilelike};
|
||||
/// use io_lifetimes::{AsFilelike, BorrowedFilelike};
|
||||
///
|
||||
/// let mut f = File::open("foo.txt")?;
|
||||
/// let borrowed_filelike: BorrowedFilelike<'_> = f.as_filelike();
|
||||
@ -258,7 +258,7 @@ pub trait IntoFilelike: IntoFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{IntoFilelike, OwnedFilelike};
|
||||
/// use io_lifetimes::{IntoFilelike, OwnedFilelike};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_filelike: OwnedFilelike = f.into_filelike();
|
||||
@ -327,7 +327,7 @@ pub trait IntoSocketlike: IntoSocket {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{IntoFilelike, OwnedFilelike};
|
||||
/// use io_lifetimes::{IntoFilelike, OwnedFilelike};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_filelike: OwnedFilelike = f.into_filelike();
|
||||
@ -359,7 +359,7 @@ pub trait FromFilelike: FromFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromFilelike, IntoFilelike, OwnedFilelike};
|
||||
/// use io_lifetimes::{FromFilelike, IntoFilelike, OwnedFilelike};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_filelike: OwnedFilelike = f.into_filelike();
|
||||
@ -376,7 +376,7 @@ pub trait FromFilelike: FromFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromFilelike, IntoFilelike};
|
||||
/// use io_lifetimes::{FromFilelike, IntoFilelike};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let f = File::from_into_filelike(f);
|
||||
@ -413,7 +413,7 @@ pub trait FromFilelike: FromHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromFilelike, IntoFilelike, OwnedFilelike};
|
||||
/// use io_lifetimes::{FromFilelike, IntoFilelike, OwnedFilelike};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_filelike: OwnedFilelike = f.into_filelike();
|
||||
@ -430,7 +430,7 @@ pub trait FromFilelike: FromHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromFilelike, IntoFilelike};
|
||||
/// use io_lifetimes::{FromFilelike, IntoFilelike};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let f = File::from_into_filelike(f);
|
||||
|
@ -25,7 +25,7 @@ pub trait AsFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{AsFd, BorrowedFd};
|
||||
/// use io_lifetimes::{AsFd, BorrowedFd};
|
||||
///
|
||||
/// let mut f = File::open("foo.txt")?;
|
||||
/// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
|
||||
@ -44,7 +44,7 @@ pub trait AsHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{AsHandle, BorrowedHandle};
|
||||
/// use io_lifetimes::{AsHandle, BorrowedHandle};
|
||||
///
|
||||
/// let mut f = File::open("foo.txt")?;
|
||||
/// let borrowed_handle: BorrowedHandle<'_> = f.as_handle();
|
||||
@ -71,7 +71,7 @@ pub trait IntoFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{IntoFd, OwnedFd};
|
||||
/// use io_lifetimes::{IntoFd, OwnedFd};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_fd: OwnedFd = f.into_fd();
|
||||
@ -91,7 +91,7 @@ pub trait IntoHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{IntoHandle, OwnedHandle};
|
||||
/// use io_lifetimes::{IntoHandle, OwnedHandle};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_handle: OwnedHandle = f.into_handle();
|
||||
@ -119,7 +119,7 @@ pub trait FromFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromFd, IntoFd, OwnedFd};
|
||||
/// use io_lifetimes::{FromFd, IntoFd, OwnedFd};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_fd: OwnedFd = f.into_fd();
|
||||
@ -136,7 +136,7 @@ pub trait FromFd {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromFd, IntoFd};
|
||||
/// use io_lifetimes::{FromFd, IntoFd};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let f = File::from_into_fd(f);
|
||||
@ -161,7 +161,7 @@ pub trait FromHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromHandle, IntoHandle, OwnedHandle};
|
||||
/// use io_lifetimes::{FromHandle, IntoHandle, OwnedHandle};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let owned_handle: OwnedHandle = f.into_handle();
|
||||
@ -178,7 +178,7 @@ pub trait FromHandle {
|
||||
/// ```rust,no_run
|
||||
/// use std::fs::File;
|
||||
/// # use std::io;
|
||||
/// use io_experiment::{FromHandle, IntoHandle};
|
||||
/// use io_lifetimes::{FromHandle, IntoHandle};
|
||||
///
|
||||
/// let f = File::open("foo.txt")?;
|
||||
/// let f = File::from_into_handle(f);
|
||||
|
14
tests/api.rs
14
tests/api.rs
@ -1,42 +1,42 @@
|
||||
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
|
||||
|
||||
use io_experiment::{
|
||||
use io_lifetimes::{
|
||||
AsFilelike, AsSocketlike, FromFilelike, FromSocketlike, IntoFilelike, IntoSocketlike,
|
||||
};
|
||||
|
||||
struct Tester {}
|
||||
impl Tester {
|
||||
fn use_file<Filelike: io_experiment::AsFilelike>(filelike: Filelike) {
|
||||
fn use_file<Filelike: io_lifetimes::AsFilelike>(filelike: Filelike) {
|
||||
let filelike = filelike.as_filelike();
|
||||
let _ = filelike.as_filelike_view::<std::fs::File>();
|
||||
let _ = dbg!(filelike);
|
||||
}
|
||||
|
||||
fn use_socket<Socketlike: io_experiment::AsSocketlike>(socketlike: Socketlike) {
|
||||
fn use_socket<Socketlike: io_lifetimes::AsSocketlike>(socketlike: Socketlike) {
|
||||
let socketlike = socketlike.as_socketlike();
|
||||
let _ = socketlike.as_socketlike_view::<std::net::TcpStream>();
|
||||
let _ = dbg!(socketlike);
|
||||
}
|
||||
|
||||
fn from_file<Filelike: io_experiment::IntoFilelike>(filelike: Filelike) {
|
||||
fn from_file<Filelike: io_lifetimes::IntoFilelike>(filelike: Filelike) {
|
||||
let filelike = filelike.into_filelike();
|
||||
let _ = filelike.as_filelike_view::<std::fs::File>();
|
||||
let _ = dbg!(&filelike);
|
||||
let _ = std::fs::File::from_filelike(filelike);
|
||||
}
|
||||
|
||||
fn from_socket<Socketlike: io_experiment::IntoSocketlike>(socketlike: Socketlike) {
|
||||
fn from_socket<Socketlike: io_lifetimes::IntoSocketlike>(socketlike: Socketlike) {
|
||||
let socketlike = socketlike.into_socketlike();
|
||||
let _ = socketlike.as_socketlike_view::<std::net::TcpStream>();
|
||||
let _ = dbg!(&socketlike);
|
||||
let _ = std::net::TcpStream::from_socketlike(socketlike);
|
||||
}
|
||||
|
||||
fn from_into_file<Filelike: io_experiment::IntoFilelike>(filelike: Filelike) {
|
||||
fn from_into_file<Filelike: io_lifetimes::IntoFilelike>(filelike: Filelike) {
|
||||
let _ = std::fs::File::from_into_filelike(filelike);
|
||||
}
|
||||
|
||||
fn from_into_socket<Socketlike: io_experiment::IntoSocketlike>(socketlike: Socketlike) {
|
||||
fn from_into_socket<Socketlike: io_lifetimes::IntoSocketlike>(socketlike: Socketlike) {
|
||||
let _ = std::net::TcpStream::from_into_socketlike(socketlike);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#![cfg_attr(not(rustc_attrs), allow(unused_imports))]
|
||||
|
||||
#[cfg(any(unix, windows))]
|
||||
use io_experiment::example_ffi::*;
|
||||
use io_lifetimes::example_ffi::*;
|
||||
#[cfg(windows)]
|
||||
use io_experiment::OwnedHandle;
|
||||
use io_lifetimes::OwnedHandle;
|
||||
#[cfg(windows)]
|
||||
use std::{convert::TryInto, ptr::null_mut};
|
||||
#[cfg(windows)]
|
||||
|
@ -4,9 +4,9 @@
|
||||
use std::mem::size_of;
|
||||
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
use io_experiment::{BorrowedFd, OwnedFd};
|
||||
use io_lifetimes::{BorrowedFd, OwnedFd};
|
||||
#[cfg(windows)]
|
||||
use io_experiment::{BorrowedHandle, BorrowedSocket, OwnedHandle, OwnedSocket};
|
||||
use io_lifetimes::{BorrowedHandle, BorrowedSocket, OwnedHandle, OwnedSocket};
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::io::RawFd;
|
||||
|
Loading…
Reference in New Issue
Block a user