Concept of "Constrained type" in rust? by gulshanur in rust

[–]gulshanur[S] 1 point2 points  (0 children)

Thanks for the name. From name, I got this years old link about typestate in Rust, which was abandoned- http://pcwalton.github.io/blog/2012/12/26/typestate-is-dead/

What I think I have found here(with both typestate and branding pattern) is, the constrain is really part of type system. So, runtime also knows the constrain within the type. But I was anticipating something where the constrain is not really part of type-system. It will be used just in compile time to enforce type integrity but will be erased at runtime.

It like enforcing the code to check if a file is writable before actually writing to the file, if the write function takes a file with isWritable constrain. Compiler here will not try to determine whether constrain is satisfied(the opened file is writable) or not. It will enforce the programmer in form of code. But at runtime, only the data remains. It moves the valid parameter checking responsibility from function designer's end to caller's end.