#PhantomData
Friggin generics without reading the docs you never know whether a FrameworkBox<Bridge> contains an actual Bridge instance or if it’s just to parametrize a PhantomData…
November 14, 2026 at 9:13 AM
ハロウィンなので、RustのPhantomDataについて解説する | yua #zenn
ハロウィンなので、RustのPhantomDataについて解説する
zenn.dev
October 31, 2026 at 6:45 PM
It's like the Send/Sync situation but worse, since there isn't even an unsafe way to expand the variance. The ONLY way to configure the variance for your type is in selecting the types of the fields, so you have to play type tetris to get the desired constraints, possibly with PhantomData
October 2, 2026 at 3:08 AM
ビルトイン関数の表現を
struct BuiltinFunction<F, A> {
_f, PhantomData<F>, _a: PhantomData<A>
}
で表現できそう
Fは関数定義を表す構造体でAは引数を表す構造体
let result = BuiltinFunction::<Hoge, HogeArgs>::invoke()?;
みたいにできる
December 21, 2025 at 5:37 AM
IAccessibleの子要素探索イテレータを作って、子要素の表現でIAccessibleをcloneしないためにライフタイムパラメータ付けたところイテレータ自身は特にライフタイム必要ないながらもライフタイムパラメータ付ける必要が出てきてPhantomDataの出番となったわけだが書き方がわからねえ!でもぐぐったら解決した!
PhantomData<&'a()>
こう!!!
なるほど型無しなので () で良いのね…
March 21, 2025 at 9:05 AM
struct Hoge<T: SomeTrait>とかしてPhantomData持ってたらなんとかならんかなとか考えてたけど
[Hoge<Foo>, Hoge<Bar>, Hoge<Baz>]
はそれぞれ型違うからだめでしょ!はい…などとやっていた
April 15, 2024 at 2:53 PM
a type-level list to enable specifying a set of subcommands in one place, without having to coordinate their names with eg an enum, is perhaps overkill, but isn't that the point
July 12, 2026 at 4:37 PM
Rust’s Zero-Sized Types (ZSTs) store no data but carry type info — powering zero-cost abstractions like PhantomData and unit structs.

Fantastic deep dive from Fillmore Labs on how Rust optimizes type safety at compile time.

👉 blog.fillmore-labs.com/posts/zerosi...

#rust #systemsprogramming
The Perils of Pointers in the Land of the Zero-Sized Type
blog.fillmore-labs.com
October 6, 2025 at 10:11 PM
7. "PhantomData of the Opera" (The Phantom of the Opera)
June 2, 2026 at 2:55 PM
Rust’s PhantomData leaves zero runtime footprint, but it powers lifetimes, variance control, and safe generics.

Why does it matter? Because sometimes, the strongest tools are invisible.
My new story breaks it down:

🔗 medium.com/@ashishjshar...

#Rust #SystemsProgramming #ZeroCost #PhantomData
Rust’s Phantom Power: The Surprising Role of PhantomData in Compile-Time Magic
Why does half the ecosystem quietly depend on a marker with zero runtime effect?
medium.com
August 7, 2025 at 11:38 AM
Gosh, how cool is PhantomData<T> though?!
December 4, 2024 at 6:59 AM
Oh nice!

Wait, y'all are nerds: doc.rust-lang.org/std/marker/s...

> A ghastly note 👻👻👻
PhantomData in std::marker - Rust
Zero-sized type used to mark things that “act like” they own a `T`.
doc.rust-lang.org
July 25, 2025 at 8:32 PM
If it were a RPG, Rust's standard library includes a few magical items, such as PhantomData.

It's used to give the type system more knowledge without requiring any runtime memory.

Do you have any favorite uses of PhantomData?
December 5, 2024 at 10:08 PM
There are also many other advanced improvements, such as allowing PhantomData tags and generic implementation of field accessors using AsRef.

The PR covers high level overview of all changes. For detailed walk through, stay tuned for more blog posts and updates on the book.
March 23, 2025 at 4:45 PM
First off, a marker struct with no fields is zero type. A marker type with a phantom data is also zero sized, like we saw in the previous thread about PhantomData.
August 14, 2025 at 7:05 AM
That's it! We've explored why and how to use PhantomData, and explored in detail how it helps us create type-safe relationships in #rustlang without runtime overhead.

Hope it helped you learn 1% more Rust today, follow me for more threads like this 🦋 🦀
April 3, 2025 at 7:05 AM
One more interesting fact before we wrap up, the best thing about PhantomData is it's a zero-sized type, so there is absolutely no performance cost to using it! 🎯

While Grade struct is 4 bytes (f32), the PhantomData itself takes up no space. It's just a compile-time type marker with no overhead! 🚀
April 3, 2025 at 7:05 AM
PhantomData is essentially a way for us to make the compiler think we are using the type T when in fact we are not.

The code using phantom data will look something like this.
April 3, 2025 at 7:05 AM
👻 Understanding PhantomData in #rustlang 🦀

Ever wondered how to create a type that depends on another type but doesn't actually contain it?

Let's explore PhantomData with a practical example of a course grading system! 👇 🧵
April 3, 2025 at 7:05 AM
the crate that implements the paper actually uses this cursed thing to constrain the lifetime of GhostCell without holding a direct reference
May 11, 2025 at 7:31 AM
Continuing on my crackpot theories of contravariant lifetimes, here's an interesting alternative formulation of Rust Pin: a pinned type holds a reference to itself (potentially inside a PhantomData). Moving the item invalidates that reference, so it invalidates the type.
January 23, 2026 at 9:06 AM