# \`self.method\` or \`obj.method\` as expression

**URL:** <https://internals.rust-lang.org/t/self-method-or-obj-method-as-expression/20591>\
**Category:** language design\
**Created:** [April 3, 2024, 1:56pm UTC](https://internals.rust-lang.org/t/self-method-or-obj-method-as-expression/20591 "2024-04-03T13:56:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MucTepDayH16](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/muctepdayh16/32/8677_2.png) [@MucTepDayH16](https://internals.rust-lang.org/u/MucTepDayH16)\
**Post date:** [April 3, 2024, 1:56pm UTC](https://internals.rust-lang.org/t/self-method-or-obj-method-as-expression/20591/1 "2024-04-03T13:56:01Z")

</div>

Want to head some comments about the thought: why `self.method` couldn't be expression e.g. be equivalent `|v| self.method(v)`. For now, methods are distinct from field and cannot be accessed as some value or function pointer. However, it is mostly similar to statefull closure, capturing `self`, and usage of `FnOnce`, `FnMut` or `Fn` can be deduced from method's receiver type.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [April 3, 2024, 2:07pm UTC](https://internals.rust-lang.org/t/self-method-or-obj-method-as-expression/20591/2 "2024-04-03T14:07:51Z")

</div>

A big problem is that fields and methods have separate namespaces, so the following is possible and indeed somewhat common:

```rust
struct Foo { bar: i32 }

impl Foo {
    fn bar(&self) -> i32 { self.bar }
}

```

Currently `foo.bar` is unambiguous, but wouldn't be if it could also refer to the method of the same name.

---

<div class="post-metadata">

**Author:** ![pitaj](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pitaj/32/11262_2.png) [@pitaj](https://internals.rust-lang.org/u/pitaj)\
**Post date:** [April 3, 2024, 3:25pm UTC](https://internals.rust-lang.org/t/self-method-or-obj-method-as-expression/20591/3 "2024-04-03T15:25:28Z")

</div>

Even more ambiguous:

```rust
struct Bar {
    foo: fn(i32) -> i32,
}
impl Bar {
    fn foo(x: i32) -> i32 { ... }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [July 2, 2024, 3:25pm UTC](https://internals.rust-lang.org/t/self-method-or-obj-method-as-expression/20591/4 "2024-07-02T15:25:49Z")

</div>

Closed on July 2, 2024, 3:25pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
