Skip to content

Instantly share code, notes, and snippets.

@ajitava-git
ajitava-git / open_file.rs
Created May 23, 2023 17:45
A function for open file operation and all possible IO errors
use std::io::ErrorKind;
fn open_file(csv_path: &str) -> Result<File, Box<dyn std::error::Error>> {
match File::open(csv_path) {
Ok(file) => Ok(file),
Err(err) => {
match err.kind() {
ErrorKind::NotFound => {
println!("File doesn't exist");
@ajitava-git
ajitava-git / partial_eq_implementation.rs
Created February 8, 2023 15:59
Implementing PartialEq for a custom type in Rust
/*
An example of implementing PartialEq for a custom type in Rust
*/
#[derive(Debug, PartialEq)]
struct Price{
amount: i32,
denomination: char
}