I don't understand what you mean by "implementing Option for a type". Option is not a trait, it's a (generic) type, "implementing it for a type" doesn't really make sense.
If you want to store a u32 value and indicate that is absent by using the maximal value, you can write a newtype wrapper around u32 and convert it to and from Option<u32>, e.g.
Sorry that my explaination is unclear, i am new to Rust.
What I want to do is to implement a Tree in Rust, and I would like to use indices to address the nodes in the tree.
pub struct Node {
pub parent: Option<NodeId>,
}
Option would use 8 instead of 4 bytes.
I would like to extend Option so, that it would check if NodeId::index equals std::u32::MAX instead of reserving 4 extra bytes, but I dont know if its possible.
I don't think so, not like that. You could try using 0 as the absent value though, then representing node IDs with Option<NonZero<u32>>, which would also avoid storing a separate discriminant.
There's nothing stopping you from using std::u32::MAX as a placeholder value just based on convention like you would in C++.
An alternative is to use Option combined with std::num::NonZeroU32 and friends as @H2CO3 said. That way you get a type-safe wrapper which will make sure you handle placeholder values, while still having the same size as a normal u32.