Can I make Result<T, E> an integer?
Can I make Result<T, E> an integer? - Lemmy.world
For context: I am trying to write a Rust wrapper over a C library. Like many C libraries, most of its functions return an int. Positive return values are meaningful (provides information) and negative values are error codes. To give an example, think of something like int get_items_from_record(const struct record *rec, struct item *items). A positive value indicates how many items were returned. -1 could mean ErrorA, -2 ErrorB, and so on. Since this is Rust, I want to represent this kind of integer as Result<T, E>, e.g.: rust enum LibError { A = -1, B = -2, // .... } type LibResult = Result<NonNegativeInteger, LibError>; Is there a way/crate to do this?