Comment

Comment by necubi

Rust has affine types (can be used no more than once), but not linear types (must be used exactly once). Linear types would be a nice feature for rust, and there's been some discussion about how to add them, but as far as I know there hasn't been any real progress there.

Affine types in Rust are anything with move semantics; for example you can create a method that consumes itself like this:

    impl A { 
      fn use(&mut self) { 
        // takes a mutable reference to self, so it
        // can be used again later
      }

      fn consume(self) {
        // moves self into this function, which means
        // it cannot be used again
      }
    }
parent necubi 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton