logoalt Hacker News

Dagonflyyesterday at 1:45 PM2 repliesview on HN

> the point of Pin is to wrap types that CAN move.

I would highlight that there are many cases where you CAN move an object safely until a certain operation requires the object to "stay put" in place.

Pin allows for that by tying the object to the place only when required. That's why Pin relates to both the object and the place.

Meanwhile, !Move types can't ever move. The object has to remain in the inital place it was constructed in. !Move requires in-place construction and emplacement to be ergonomic at all.


Replies

10000truthsyesterday at 7:03 PM

> I would highlight that there are many cases where you CAN move an object safely until a certain operation requires the object to "stay put" in place.

You could model this with a state machine enum where the "stay put" phase is a variant that accepts a !Move, like so:

  enum StateMachine<PinnedState: ?Move> {
      InitialState,
      State1(String),
      State2(Box<PinnedState>),
      TerminalState,
  }
Mond_yesterday at 6:08 PM

Stupid question, can't this trivially be solved by having a movable constructor / builder type that then gets turned into a non-movable type when built?

show 1 reply