简体   繁体   English

Rust 吸气剂-返回型

[英]Rust Getter - return type

Is there a way to replace in a "getter" method the return type有没有办法在“getter”方法中替换返回类型

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谢谢

No, Rust doesn't have anything like this.不,Rust 没有这样的东西。 You can generate getters using a macro, if you want to save typing.如果要节省输入,可以使用宏生成 getter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM