rust-course
rust-course copied to clipboard
关联函数定义
https://github.com/sunface/rust-course/blob/e01f9c2e4595992690f00e18b60277d2e67ee401/src/basic/method.md?plain=1#L205 从 Rust-Lang Book 此处的原文来看
All functions defined within an
impl
block are called associated functions because they’re associated with the type named after theimpl
. 那么它的意思应该是 对应类型定义在impl
块中的函数都是 该类型的 关联函数 其中带有self
的被称为方法(即 方法也是关联函数)
评论区此处提到过
method 和 function 存在区别吧
感觉从概念上讲 method 是 第一个参数类型为 Self 的 function
f.read()
像是 read(f)
或者read(&f)
的语法糖