Rust: Or Type

This is a proposal for Rust to add a new construct: “or type”. We can also call them “anonymous enum”.

fn main() {
    // to define "or type" or "anonymous enum".
    let x: i32 or String = 10;

    match x {
        i: i32 => {
        s: String => {

Compiler can also figure out somethings eg:

fn foo() -> i32 {

fn main() {
    let x: i32 or String = foo();

Not only it saves us from creating one off enums, it also allows pattern that are not possible with explicit enums:

fn foo() -> i32 or String {

fn main() {
    let x: i32 or String or i64 = foo();

Not sure what the complications could be.

Prior work: anonymous sum types, don’t like their syntax, reem: anonymous enums, pretty much what I wanted, scialex: anonymous enums, also pretty similar. Also this thread on rust internals.

Seems people are split on should match be allowed, I prefer that, I prefer there was no trait complication, we do not put trait in enum as well, only concrete types. I also prefer A or B not having any way to implement anything, anything implemented by both A and B is already implemented on A or B. Some other people feel it should only be traits and no match: with that I believe its already possible today since impl Trait landed.

Table Of Content

Immobile v2


Rust: Or Type

Project Primer

Link Log

Oct 2020

August 2020

July 2020

June 2020

May 2020

April 2020

March 2020

February 2020

January 2020


Books Have Read / Recommend

Product Management Books

Badass: Making Users Awesome


Five Cs of An Organisation

Success and failure of encryption

Open Source

Observer: Observability for Rust

Realm: Web Development Framework Using Rust and Elm

MartD: Server To Browser Messages

On Writing And Formats Of Written Communications

Rust Stuff

fbt: Folder Based Test-Runner

dmax: Cargo Dependency Updater

Rust feature flags

Why is diesel not compatible with async?

Making Postgres Only Diesel Code To Also Support Sqlite

Rust Git2’s Concepts

Git Hash And Build Date In Rust Build

Systray Only Native App In Rust

Software and Tools I Use Often


DNS Over HTTPS Controversy

The Patel Motel Cartel

Standalone Complex


January 2020

Word Of The Day





Nix On OSX Catalina

Postgres: WAL / Logical Decoding

Postgres: Listen-Notify



Go All The Way

SSH Commands



SHA256 vs SHA224

Pronouns Bad


Web Components

Early Return