Rust learning: lessons, notes, and exercise crates
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "learn-panic"
|
||||
version = "0.1.0"
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "learn-panic"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1 @@
|
||||
alkdsfjlkafdsj
|
||||
@@ -0,0 +1,30 @@
|
||||
use std::{fs::File, io::ErrorKind, panic};
|
||||
fn main() {
|
||||
let _v = vec![1, 2, 3];
|
||||
|
||||
let greeting_file_result = File::open("hello.txt");
|
||||
|
||||
let _greeting_file = match greeting_file_result {
|
||||
Ok(file) => file,
|
||||
Err(error) => match error.kind() {
|
||||
ErrorKind::NotFound => match File::create("hello.txt") {
|
||||
Ok(fc) => fc,
|
||||
Err(e) => panic!("Problem creating the file: {e}"),
|
||||
},
|
||||
_ => {
|
||||
panic!("Problem opening the file: {error:?}");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// v[99];
|
||||
}
|
||||
|
||||
use std::io::{self, Read};
|
||||
|
||||
fn read_username_from_file() -> Result<String, io::Error> {
|
||||
let mut username_file = File::open("hello.txt")?;
|
||||
let mut username = String::new();
|
||||
username_file.read_to_string(&mut username)?;
|
||||
Ok(username)
|
||||
}
|
||||
Reference in New Issue
Block a user