https://mstdn.nere9.help/@orange_in_space/101266366644177728
これ、
impl Hoge {
fn hoge1(self) -> Self;
fn hoge2(&self) -> &Self;
fn hoge3(&mut self) -> &mut Self;
fn hoge4(&mut self) -> Self;
// などなど
}
のどれのつもりで言ってるのかわからないんですが (これらが区別できない言語はまず弱い)
C++ で言うなら、
struct Hoge {
const Hoge &hoge1() const;
Hoge &hoge2() const;
Hoge hoge3() const;
const Hoge &hoge4();
Hoge &hoge5();
Hoge hoge6();
};
くらいの使い分けはできるわけで、たとえば hoge4,5,6 が自身を変更するであろうというのは明らかだし、 hoge1,2 が自身か自身の所有するオブジェクトの参照を返すだろうというのも明らかですよね、そして hoge3 は自身のコピーか別オブジェクトを返す (いずれにせよ所有権は別になりそう) というのもわかる