Yes, exactly! Rust lets you encode a lot more into your types than what you would normally be used to in other languages.

Regarding errors, if there’s semantic meaning attached to the negative ints in the API, you might want to have an Error type that captures that meaning on Rust side. Look into the thiserror crate that lets you easily spin up custom error types.

Reply to this note

Please Login to reply.

Discussion

Yes. I started creating an online learning app for myself and encoded the negative to mean things like "never set," "user deleted," "missing data," etc. I don't think think I've used more (or lesser? 🤷‍♂️) than -3 in my code, but nothing prevents my using the whole range of an i8 in rust while also having robust exception handling.