Why is `From` an Exception in the Orphan rule?

⚓ Rust    📅 2026-06-01    👤 surdeus    👁️ 1      

surdeus

Generally speaking, the orphan rule can be described as:

*You can only implement a trait for a type if either the trait or the type is defined in your own crate.medium

Normally, this rule prevents any type from having traits implemented for them outside the crate. For example, it would be impossible to implement a Display trait for f32 or String outside the std. However, the From trait seems to be an exception to this rule.
For example:

///Stores the Amount of used Entitys of this kind
#[derive(Resource, Default, Clone, From)]
pub struct Count(pub usize);
impl From<Count> for usize {
    fn from(val: Count) -> Self {
        val.0
    }
}

example
Dosen't produce compiler Errors anymore. Why exactly is that? There are another Traits, that can do that?

6 posts - 5 participants

Read full topic

🏷️ Rust_feed