# What is the Julia equivalent of Rust Option\<T\>?

**URL:** https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-rust-option-t/122134
**Category:** New to Julia
**Tags:** question
**Created:** [November 1, 2024, 1:55pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-rust-option-t/122134 "2024-11-01T13:55:09Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [November 1, 2024, 3:41pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-rust-option-t/122134/11 "2024-11-01T15:41:44Z")

</div>

I found this old blog post that does a better job of differentiating Julia’s `Union` and Rust’s sum types. The sections on the practical pros and cons for either approach are of particular interest. Link: [Union vs sum types](https://viralinstruction.com/posts/uniontypes/)

I would guess that the only reason sum types aren’t utilized as much in Julia is that type optimization tends to go to extremes. Ideally you have perfect type inference in a generic method; you might get `nothing` and `missing` in some contexts, but those don’t escalate to more types (operations on `missing` propagate to `missing`, ones on `nothing` error) and are quickly handled. People don’t tend to maintain custom small `Union`s through a method, and why would they when the compiler only tracks a few? When there are more, maybe even infinite, types the compiler cannot generally track, optimization then becomes about isolating the dynamic dispatches to small caller methods, and the JIT-compiled callees can be perfectly inferred again. The middle ground of telling the compiler the finite number of types you handle with more care is more necessary for a AOT-compiled language. AOT-compiled juliac is being developed for its lower overhead, and I predict that sum types will become far more appreciated when the JIT compiler and its flexibility isn’t around.

---

_[View the full topic](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-rust-option-t/122134)._
