Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Found the internet!
r/rust
r/rust
5
Posted by2 months ago

[ANN] match_deref. I made a proc-macro lib for long-awaited deref patterns

I made a proc-macro lib for long-awaited deref patterns! https://crates.io/crates/match_deref . Example:

use std::rc::Rc;

enum Value {
    Nil,
    Cons(Rc<Value>, Rc<Value>),
    Symbol(String),
}

use Value::*;

let v: &Value = todo!();
match_deref::match_deref!{
    match v {
        Nil => todo!(),
        Cons(Deref @ Symbol(Deref @ "quote"), Deref @ Cons(x, Deref @ Nil)) => todo!(),
        _ => todo!(),
    }
}

I think my library is invaluable in writing interpreters, compilers, provers etc.

There exists ongoing work to add deref patterns to rustc. But with my lib you can use them right now, in stable Rust.

This is my very first lib in crates.io

0 comments
85% Upvoted

no comments yet

Be the first to share what you think!

We use cookies on our websites for a number of purposes, including analytics and performance, functionality and advertising. Learn more about Reddit’s use of cookies.