Skip to content

Commit

Permalink
Merge pull request #382 from damoasda/fix-11-1
Browse files Browse the repository at this point in the history
Codebeispiel aktualisieren
  • Loading branch information
damoasda authored Dec 8, 2024
2 parents 12ceb66 + 800ab6d commit 0bfcba8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/ch11-01-writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,20 +1119,25 @@ der Test aus Codeblock 11-1 so umgeschrieben, dass er `Result<T, E>` verwendet
und `Err` zurückgibt, anstatt das Programm abzubrechen:

```rust,noplayground
# #![allow(unused_variables)]
# fn main() {}
# pub fn add(left: usize, right: usize) -> usize {
# left + right
# }
#
# #[cfg(test)]
# mod tests {
# use super::*;
#
#[cfg(test)]
mod tests {
#[test]
fn it_works() -> Result<(), String> {
if 2 + 2 == 4 {
let result = add(2, 2);
if result == 4 {
Ok(())
} else {
Err(String::from("zwei plus zwei ist nicht gleich vier"))
}
}
}
# }
```

Die Funktion `it_works` hat jetzt den Rückgabetyp `Result<(), String>`. Anstatt
Expand Down

0 comments on commit 0bfcba8

Please sign in to comment.