Naming of Option and Result returning functions
I have a lot of functions and methods which return either Option or Result, is there a naming convention for such functions? I need to distinguish them as there often two variants of the same function -- one returning Option (which is cheap) and one returning Result (which could be very expensive). For now, I'm using this:
fn mm(&self) -> Option<FragModelRef>;
fn mm_or_err(&self) -> Res<FragModelRef> {
self.mm().ok_or_else(|| diag_err!("can't find metamodel"))
}
But I want to get rid of the _or_err()? on every line of my sources. So I consider something like:
fn mm_opt(&self) -> Option<FragModelRef>;
fn mm(&self) -> Res<FragModelRef> {
self.mm_opt().ok_or_else(|| diag_err!("can't find metamodel"))
}
Any suggestions or thoughts?
Posted Aug 8, 2018, 10:38 AM UTC
417