My function might fail, but it doesn't return result, the empty type in rust is ()
as such takes up 0 bytes, if Option is defined like that
pub enum Option<T> {
None,
Some(T),
}
It shouldn't have overhead (on return) at all, because the tag only takes up 1 byte, just like the boolean. Is that correct? Upon inspecting Compiler Explorer disassembly output I found out that they produce exactly the same code, but I still wonder if that is correct for all cases, is there cases where returning empty option might have an overhead?
The convenience of Option<()>
over bool
is unwrapping and handling functions
Just in case my function that returns empty option will be called a lot.