Posts

January 04, 2019
Just a quick update. I compiled all my Rust posts into a book and I’ve published it here here. I also have it available on Smashwords and Medium. Over the last two months, I’ve been working heavily developing the infrastructure for Chainetix using Habitat. While I was working on our codebase, I realised that a good deal of the core-plans repository was lacking and out of date. I have been putting a ton of love into that in my personal time.
September 29, 2018
Previously on Code Artistry, we learned how to parallelise our functions. Now let’s see how we can measure the performance increase. While version: pub fn increaseABVMaths(allInputs: &increaseABVData) -> finalSugarFloat { let mut newStartingBrix: f64 = allInputs.startingBrix; let mut newEstimatedABV: f64 = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0; while newEstimatedABV < allInputs.desiredABV { newStartingBrix = newStartingBrix + 0.001; newEstimatedABV = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0; } ... Parallelised version: pub fn increaseABVMaths(allInputs: &increaseABVData) -> finalSugarFloat { let mut newStartingBrix: f64 = allInputs.
September 29, 2018
Let’s make things better today. We’re humans. We’re horrible at repetition. We like entertainment. For repetitive tasks, we have tools like loops that we can utilise. An example from BrewStillery looked like this originally: pub fn increaseABVMaths(allInputs: &increaseABVData) -> finalSugarFloat { let mut newStartingBrix: f64 = allInputs.startingBrix; let mut newEstimatedABV: f64 = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0; while newEstimatedABV < allInputs.desiredABV { newStartingBrix = newStartingBrix + 0.001; newEstimatedABV = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0; } ... What’s going on is newStartingBrix is a user inputted f64.
July 18, 2018
Continuing on from our last post, let’s say we wanted to use a borrowed value for whatever reason (like we want our original variable to live after the function call): #![allow(non_snake_case, non_camel_case_types)] trait mathyMaths { fn cubeIt(&self) -> f64; } impl mathyMaths for f32 { fn cubeIt(&self) -> f64 { (self as f64).powi(3) } } impl mathyMaths for f64 { fn cubeIt(&self) -> f64 { self.powi(3) } } fn main() { let cubeMe: f32 = 3.
July 17, 2018
In our last post, we implemented methods (functions in an impl block) for our custom enum. What happens if we want to implement something for a type we didn’t create? This is where traits come into play. We’re going to start with a program like this: #![allow(non_snake_case, non_camel_case_types)] fn cubeIt(inputNumber: f64) -> f64 { inputNumber.powi(3) } fn main() { let cubeMe: f64 = 3.33; println!("{}", cubeIt(cubeMe)); } This outputs: