External Publication
Visit Post

Should we have set static field for Trait?

Rust Internals [Unofficial] March 6, 2026
Source

I want something like this:

trait Person
where Self::name:&str /* This should be Self::Person::name -> It's still compicate*/
{
fn name(&self)->Self.name{
self.name
}
}

or we can do it by

 #[field(name,...)] /* It can create  **bad code** and bad habbit  */
trait Person{}

rightnow I am doing like this :

struct Person{
fulname: String,
midname:String,
....
}
trait Identify {
fn person(&self)->&Person;
fn fname(&self)->&str{
self.person().fulname
}
fn mname(&self)->&str{
self.person().midname
}
....

and it's quite boring.we have getters crate. but I doesn't want to use it yet

P/S : I have changed my mind. Actually Op3 is better then option1 and option2. Nothing should be change

Discussion in the ATmosphere

Loading comments...