self 和 Self 和有什么不一样? [英] What's the difference between self and Self?

查看:60
本文介绍了self 和 Self 和有什么不一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档中没有遇到过 Self,只有在源代码中.该文档仅使用 self.

I haven't come across Self in the documentation, only in the source code. The documentation only uses self.

推荐答案

self 当用作第一个方法参数时,是 self: Self 的简写.还有&self,相当于self: &Self,还有&mut self,相当于self: &mut Self.

self when used as first method argument, is a shorthand for self: Self. There are also &self, which is equivalent to self: &Self, and &mut self, which is equivalent to self: &mut Self.

Self 是方法接收类型的语法糖(即该方法所在的类型).这也允许泛型类型没有太多重复.

Self in method arguments is syntactic sugar for the receiving type of the method (i.e. the type whose impl this method is in). This also allows for generic types without too much repetition.

这篇关于self 和 Self 和有什么不一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆