Why can I call File.take() on a reference?

前端 未结 1 1087
鱼传尺愫
鱼传尺愫 2021-01-19 12:27

When I look at File\'s docs, I see that the take method takes a self, not a &self. But I\'m still able to call the method on a bor

相关标签:
1条回答
  • 2021-01-19 13:06

    The take method comes from the Read trait. That trait is implemented on File, so there is a method File::take(self, u64) -> Take<Self>, but the trait is also implemented on &File (the impl is even listed on the very page you link to). For that impl, the Self type is &File, so its take method takes a reference.

    0 讨论(0)
提交回复
热议问题