Hi,
I was wondering which name is better to use for a constructor that returns an Option
.
Suppose a simple struct that represents a integer range (ignoring that already exists std::ops::Range
) and suppose that you want to avoid reversed range:
struct Range {
start: i32,
end: i32,
}
impl Range {
/// Create a range with provided values only
/// if start is not greater than end
fn put_a_name_here(start: i32, end: i32) -> Option<Self> {
if start <= end {
Some(Range{ start, end })
}
else {
None
}
}
}
I didn't find a clear suggestion for cases like this in the API guidelines.
Thank you.