What is the difference between &Trait and impl Trait when used as method arguments?

后端 未结 2 1169
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 03:25

In my project so far, I use many traits to permit mocking/stubbing in unit tests for injected dependencies. However, one detail of what I\'m doing so far seems so suspicious

2条回答
  •  情书的邮戳
    2020-12-11 03:36

    It is indeed different. The impl version is equivalent to the following:

    fn confirm>(subject: M) ...
    

    so unlike the first version, subject is moved (passed by value) into confirm, rather than passed by reference. So in the impl version, confirm takes ownership of this value.

提交回复
热议问题