diff options
| author | hybrid <hybrid@hybridlabs.cc> | 2026-10-16 12:37:15 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.cc> | 2026-10-16 12:37:15 +0300 |
| commit | 256ad69edea8bb5eeff38e3f5fa1dcf6e990daf7 (patch) | |
| tree | 1341d67aa4b4fcdf3ec21306b90ee894b721bbaa /src/panic | |
| parent | 43ddbb814e679bf2adde3a8602624c207641dca2 (diff) | |
| download | rust-book-256ad69edea8bb5eeff38e3f5fa1dcf6e990daf7.tar.gz rust-book-256ad69edea8bb5eeff38e3f5fa1dcf6e990daf7.tar.bz2 rust-book-256ad69edea8bb5eeff38e3f5fa1dcf6e990daf7.zip | |
add: generics, panic
Diffstat (limited to '')
| -rw-r--r-- | src/panic/Cargo.toml | 6 | ||||
| -rw-r--r-- | src/panic/src/main.rs | 23 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/panic/Cargo.toml b/src/panic/Cargo.toml new file mode 100644 index 0000000..94b8cff --- /dev/null +++ b/src/panic/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "panic" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/panic/src/main.rs b/src/panic/src/main.rs new file mode 100644 index 0000000..bf8be55 --- /dev/null +++ b/src/panic/src/main.rs @@ -0,0 +1,23 @@ +struct Test <T> { + a: T, + b: T, +} + +#![allow(unused)] +fn main() { + use std::fs::File; + use std::io::{self, Read}; + + fn read_username_from_file() -> Result<String, io::Error> { + let username_file_result = File::open("/tmp/hello.txt"); + + let mut username_file = username_file_result?; + + let mut username = String::new(); + + username_file.read_to_string(&mut username)?; + Ok(username) + } + + println!("username: {}", read_username_from_file().unwrap()); +} |
