Rust invoke trait method on generic type parameter

前端 未结 2 1814
小鲜肉
小鲜肉 2021-01-12 04:29

Suppose I have a rust trait that contains a function that does not take a &self parameter. Is there a way for me to call this function based on a generic type parameter

2条回答
  •  无人及你
    2021-01-12 04:48

    Unfortunately, this isn't currently possible. It used to be, based on a implementation detail, however that was removed in favor of eventually implementing a proper way of doing this.

    When it is eventually implemented, it may end up looking something like this: TypeTrait::::type_id(), however there is, currently, no syntax set in stone.

    This is a known case and one that is fully intended to be supported, it is just unfortunate that it currently is not possible.

    The full discussion about this topic (called associated methods) is here: https://github.com/mozilla/rust/issues/6894 and here: https://github.com/mozilla/rust/issues/8888

提交回复
热议问题