Skip to content

Commit

Permalink
fix typo: remove extra '}' in API walk-through
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Karami committed Nov 8, 2024
1 parent 936b639 commit e7c9258
Showing 1 changed file with 51 additions and 53 deletions.
104 changes: 51 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,72 +58,70 @@ types, `input-stream`, and `output-stream`, which support `read` and
#### Use Case: copying from input to output using `read`/`write`

```rust
fn copy_data(input: InputStream, output: OutputStream) -> Result<(), StreamError> {
const BUFFER_LEN: usize = 4096;

let wait_input = [subscribe_to_input_stream(input)];
let wait_output = [subscribe_to_output_stream(output)];

loop {
let (mut data, mut eos) = input.read(BUFFER_LEN)?;

// If we didn't get any data promptly, wait for it.
if data.len() == 0 {
let _ = poll_list(&wait_input[..]);
(data, eos) = input.read(BUFFER_LEN)?;
}

let mut remaining = &data[..];
while !remaining.is_empty() {
let mut num_written = output.write(remaining)?;

// If we didn't put any data promptly, wait for it.
if num_written == 0 {
let _ = poll_list(&wait_output[..]);
num_written = output.write(remaining)?;
}

remaining = &remaining[num_written..];
}
if eos {
break;
}
}
Ok(())
}
fn copy_data(input: InputStream, output: OutputStream) -> Result<(), StreamError> {
const BUFFER_LEN: usize = 4096;

let wait_input = [subscribe_to_input_stream(input)];
let wait_output = [subscribe_to_output_stream(output)];

loop {
let (mut data, mut eos) = input.read(BUFFER_LEN)?;

// If we didn't get any data promptly, wait for it.
if data.len() == 0 {
let _ = poll_list(&wait_input[..]);
(data, eos) = input.read(BUFFER_LEN)?;
}

let mut remaining = &data[..];
while !remaining.is_empty() {
let mut num_written = output.write(remaining)?;

// If we didn't put any data promptly, wait for it.
if num_written == 0 {
let _ = poll_list(&wait_output[..]);
num_written = output.write(remaining)?;
}

remaining = &remaining[num_written..];
}
if eos {
break;
}
}
Ok(())
}
```

#### Use case: copying from input to output using `splice`

```rust
fn copy_data(input: InputStream, output: OutputStream) -> Result<(), StreamError> {
let wait_input = [subscribe_to_input_stream(input)];

loop {
let (num_copied, eos) = output.splice(input, u64::MAX)?;
if eos {
break;
}

// If we didn't get any data promptly, wait for it.
if num_copied == 0 {
let _ = poll_list(&wait_input[..]);
}
}
Ok(())
}
fn copy_data(input: InputStream, output: OutputStream) -> Result<(), StreamError> {
let wait_input = [subscribe_to_input_stream(input)];

loop {
let (num_copied, eos) = output.splice(input, u64::MAX)?;
if eos {
break;
}

// If we didn't get any data promptly, wait for it.
if num_copied == 0 {
let _ = poll_list(&wait_input[..]);
}
}
Ok(())
}
```

#### Use case: copying from input to output using `forward`

```rust
fn copy_data(input: InputStream, output: OutputStream) -> Result<(), StreamError> {
output.forward(input)?;
Ok(())
}
fn copy_data(input: InputStream, output: OutputStream) -> Result<(), StreamError> {
output.forward(input)?;
Ok(())
}

```

### Detailed design discussion
Expand Down

0 comments on commit e7c9258

Please sign in to comment.