It’s quite simple. Just remove the permalink
field! If you are calculating it then no need to store it in the struct.
If you do need the field to be there (ex you serialise it with serde), then create a method called new
that takes everything but the permalink, construct your permalink there, then return a new object.
Your permalink method can now just be self.permalink.to_string()
P.S. in the second case I’d recommend to change the return type of self.permalink()
to &str
. It avoids unnecessary cloning of the string.
Technically yes, but a newbie doesn’t need that. I doubt it’s an application that performance is so critical either.
Too much premature optimisation IMO