Goudounov
Goudounov

Reputation: 11

Rust Getter - return type

Is there a way to replace in a "getter" method the return type

pub struct Foo {
  key: MyKey,
  value: usize,
}


impl Foo {
  pub fn value(&self) -> usize {
    ...
  }
}

by something like:

pub fn value(&self) -> Typeof(Self.value) { ... }

Thanks

Upvotes: 1

Views: 237

Answers (1)

Peter Hall
Peter Hall

Reputation: 58735

No, Rust doesn't have anything like this. You can generate getters using a macro, if you want to save typing.

Upvotes: 1

Related Questions