What's the meaning of "cannot be derived"?

I read the std::fmt::Display doc here: https://doc.servo.org/std/fmt/trait.Display.html
It says "Display is similar to Debug, but Display is for user-facing output, and so cannot be derived.

Who can help to explain me what’s the exact meaning of “can’t be derived” ?

Does that mean the fmt::Display impl of any struct in external crate the Display can’t be used?

It means that there is no implementation for #[derive(Display)] in the standard library, see https://play.rust-lang.org/?gist=70de3c26d46537a315e92867701a0ae8&version=stable&mode=debug&edition=2015. Since it’s user facing and output is dependant on context, a general implementation would not suffice.

There is one for Debug because it’s meant to create a detailed programmer facing string of the implementing object. Which would be a (filtered) key-value dump in practise. Debug docs

1 Like

Thanks Bert , clear now.

I’m facing an odd issue which has fmt::Display works normal in local but works different if use it as extern crate, that’s why I’m confusing about the 'derived` word in doc. the odd issue could be another topic.

You are only allowed to implement Display for types in the same crate. You can’t add Display to a type from another crate. This is called “orphan rules” in Rust.

1 Like