This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anyhow::{Context}; | |
use std::fs::File; | |
use std::io::{Read}; | |
fn read_file_contents(path: &str) -> tomercode_error::Result<String> { | |
let contents = open_file(path).with_context(|| format!("Failed to open file: {}", path))?; | |
let processed_contents = process_contents(&contents).context("could not process file contents")?; | |
Ok(processed_contents) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Person { | |
name: String, | |
age: u32, | |
address: String, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub type Result<T, E = TomerCodeError> = anyhow::Result<T, E>; | |
#[derive(Error, Debug)] | |
pub enum TomerCodeError { | |
#[error("Invalid state error: {0}")] | |
InvalidState(anyhow::Error), | |
#[error("Connection Error Occoured: {0}")] | |
ConnectionError(String), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn log(value: &String) -> Result<(), LoggingError> { | |
if value.len() > 10 { | |
return Err(LoggingError::TooLong); | |
} | |
println!("{}", value); | |
Ok(()) | |
} | |
fn get_registry_value(key_path: &str) -> Result<String, io::Error> { | |
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Error, Debug)] | |
pub enum TomerCodeError { | |
#[error("Invalid state error: {0}")] | |
InvalidState(String), | |
#[error("Connection Error Occoured: {0}")] | |
ConnectionError(String), | |
#[error("Registry Error Occoured: {0}")] | |
RegistyError(#[from] io::Error), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn get_registry_value(key_path: &str) -> Result<String, io::Error> { | |
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); | |
let key = hklm.open_subkey(key_path)?; | |
let value: String = key.get_value("my_key")?; | |
Ok(value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn some_or_go_get_from_db(some_value: Option<i32>) { | |
let value = some_value.or_else(|| db.get()); | |
println!("Value: {}", value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First Project (ModuleA) | |
class ModuleA: | |
def __init__(self, module_b: ModuleB, module_c: ModuleC): | |
print('im code from module A') | |
module_b.hello() | |
module_c.hello() | |
def hello(self): | |
print('hello from A') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def was_created_today(machine: vim.VirtualMachine) -> bool: | |
date = _get_date_from_name(machine.name) | |
# return some implemetation that checks if date is today | |
def _get_date_from_name(name: str) -> datetime.date: | |
# return some implementation that extracts date from name of machine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def was_created_today(machine) -> bool: | |
date = _get_date_from_name(machine.name) | |
date_now = datetime.datetime.now().date() | |
return (date_now - date).days > 0 |
NewerOlder