Skip to content

Commit

Permalink
Textänderungen aus dem Originaltext übernehmen
Browse files Browse the repository at this point in the history
  • Loading branch information
damoasda committed Sep 30, 2023
1 parent 3529d17 commit 0ee7d3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/ch20-01-single-threaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ Code in Codeblock 20-3.
<span class="filename">Dateiname: src/main.rs</span>

```rust,no_run
# use std::io::prelude::*;
# use std::net::TcpListener;
# use std::net::TcpStream;
# use std::{
# io::{prelude::*, BufReader},
# net::{TcpListener, TcpStream},
# };
#
# fn main() {
# let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
Expand All @@ -351,14 +352,16 @@ Code in Codeblock 20-3.
# }
#
fn handle_connection(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();
let buf_reader = BufReader::new(&mut stream);
let http_request: Vec<_> = buf_reader
.lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();
let response = "HTTP/1.1 200 OK\r\n\r\n";
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
stream.write_all(response.as_bytes()).unwrap();
}
```

Expand Down
12 changes: 6 additions & 6 deletions src/ch20-02-multithreaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ annimmt:

<span class="filename">Dateiname: src/lib.rs</span>

```rust
```rust,noplayground
# pub struct ThreadPool;
#
impl ThreadPool {
Expand Down Expand Up @@ -608,7 +608,7 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T>
where
F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static
T: Send + 'static,
```

Die Funktion `spawn` gibt einen `JoinHandle<T>` zurück, wobei `T` der Typ ist,
Expand Down Expand Up @@ -990,12 +990,12 @@ Wenn wir versuchen, diesen Code zu überprüfen, erhalten wir diesen Fehler:
$ cargo check
Checking hello v0.1.0 (file:///projects/hello)
error[E0382]: use of moved value: `receiver`
--> src/lib.rs:27:42
--> src/lib.rs:26:42
|
22 | let (sender, receiver) = mpsc::channel();
21 | let (sender, receiver) = mpsc::channel();
| -------- move occurs because `receiver` has type `std::sync::mpsc::Receiver<Job>`, which does not implement the `Copy` trait
...
27 | workers.push(Worker::new(id, receiver));
26 | workers.push(Worker::new(id, receiver));
| ^^^^^^^^ value moved here, in previous iteration of loop

For more information about this error, try `rustc --explain E0382`.
Expand Down Expand Up @@ -1155,7 +1155,7 @@ impl ThreadPool {
#
# ThreadPool { workers, sender }
# }
#
pub fn execute<F>(&self, f: F)
where
F: FnOnce() + Send + 'static,
Expand Down

0 comments on commit 0ee7d3b

Please sign in to comment.