News for hackers. Stuff that matters.
Re:Thoughts on Rust, a few thousand lines in by Misdicorl on Wednesday January 09, 2019 @05:31PM (#18869681)
I believe the way this is solved is by having the type of escaped(foo) different than that of parse(foo) and only accepting a EscapedString in doBaz and an ParsedString in doBar.

Your type structure at no extra runtime cost is String : ParsedString : EscapedString.

This ensures you don't escape strings before parsing them too. Nice!

Re:Thoughts on Rust, a few thousand lines in by afraca on Thursday January 10, 2019 @03:49AM (#18872468)
This is common in Haskell as well using `newtype`. You can have type aliases like

  type A = B
but you can use the following function with a B:

  f :: A -> _
whereas

  newtype EscapedString = EscapedString String
  f' :: EscapedString -> _
would prevent from using f' with the wrong data. Newtype is a zero-cost abstraction.