What to choose: self->Self or &mut self->&mut Self

struct A;

impl A {
    fn then_owned(self, _: i32) -> Self {

    fn then_mut(&mut self, _: i32) -> &mut Self {

fn pass_a(_: A) {}

fn main() {
        let mut a = A;

What is faster? What is better? And why?


I would prefer the mutable solution as it enables people (for various reasons useful) to call every method on one instance, if none of the below reasons seem applicable.




However, these kind of pattern, the builder pattern, should be uniform, meaning it should be the same pattern for all methods.
This could limit your ability to introduce new features later.

You could for example decide to have a method that could Err. (fn something(self,_: i32) -> Result<Self,SomeError>)
In this case you have the two options, &mut or owned.
It is now depending on whether you like to consume the value in case of an Err or leave it up to the user to retry or use the half-built structure otherwise.

You could also decide to introduce a method returning a different type that owns the passed one.
It would be good if you’d choosen to use the owned version then, as again, every function signature should use the same pattern.