How to lazily create map entry whose construction uses self in Rust

前端 未结 2 1676
别跟我提以往
别跟我提以往 2021-01-06 02:40

I\'m trying to implement a lazy-construction / memoized evaluation / caching idiom in Rust.

There\'s an outer type which has a bunch of data and an accessor method.

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-06 02:53

    So, the primary motivation for me wanting to pass Thing as an argument to ContainedThing::create was to use Thing's API to help in the construction. However, it turns out that I'll want it to be borrowed mutably, because I need recursive memoized construction here, and that makes it a cycle problem.

    So, it looks like my separated check + insert logic is here to stay.

提交回复
热议问题