New week, new Rust! What are you folks up to?
For the past few weeks I've been rewriting a high-performance transmission system from C++ to Rust, and will continue to do so this week.
I'm a little hyped to be honest, because the port is probably around 50% done, but it's already so much more robust than the old code. And it does a pretty neat job of fusing async and sync, to get the best of both worlds.
Forever grateful to all the people participating on these forums -- there's traces of so many of you in the code I write; in particular in this project.
I'm dusting off (rusting off?) the trait-gen crate.
It's a procedural macro. I've finally taken the time to update it to syn
version 2, which came with a series of breaking changes. In the process, I'm adding a feature and improving the error messages.
At the same time, I'm taking this opportunity to read Write Powerful Rust Macros, by Sam Van Overmeire. It's a very good book on the subject!
PS: Here's an example of what it does, below: the attributes generate the two implementations for all the types in the list. It's more flexible than blanket implementations (and can be used on other implementations than traits), and clearer to read than declarative macros, which are often used for implementing similar code on a series of types.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Metre(pub f64);
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Foot(pub f64);
trait Metrics {
const TO_METRE: f64;
fn to_metre(&self) -> f64;
}
#[trait_gen(T -> Metre, Foot)] // implements for the two types
impl Metrics for T {
#[trait_gen_if(T in Metre)] // conditional code
const TO_METRE: f64 = 1.0;
#[trait_gen_if(T in Foot)]
const TO_METRE: f64 = 0.3048;
fn to_metre(&self) -> f64 {
self.0 * Self::TO_METRE
}
}
#[trait_gen(A -> Metre, Foot)] // implements for the 4 type combinations
#[trait_gen(B -> Metre, Foot)]
impl Add<B> for A {
type Output = A;
fn add(self, rhs: B) -> Self::Output {
A((self.to_metre() + rhs.to_metre())/Self::TO_METRE)
}
}
Still working on my chess engine. Currently approaching a rating of ~2500 elo which is almost grandmaster level. Hoping to get to a superhuman level soon!
I spent the weekend working on a Rust rewrite of LiveTagger (a little CLI that I built for batch tagging samples in Ableton Live) - mainly because I wanted an excuse to play around with clap
for the first time in a while
After several hours of bashing my head against a brick wall trying to parse the XMP metadata with quick-xml
[1], I found out that Adobe actually has official Rust bindings for their XMP SDK now, which is neat.
Which, to be clear, is a great library - my brain was just too small to figure out how to use a pull parser for this... âŠī¸