Currently, we first try to decode the value normally. If decoding fails (because it's null), an error is created. For Option<T>, we then drop that error and return None instead. This means decoding an optional value still constructs an error string on the failure path, which adds unnecessary allocation and overhead.
Ideally, we should provide a blanket implementation for Option<T>. Then users would only need to implement the conversion from our value for their own types.
This is a breaking change because it requires users to rewrite all their implementation to add the new method.
Example:
trait TryGetable {
fn try_get_by<I: ColIdx>(
row: &QueryResult,
index: I,
) -> Result<Self, TryGetError> {
let value = row.value(index)?;
Self::try_from_value(value)
}
}
impl<T> TryGetable for Option<T> {
fn try_from_value(value: &Value) {
if value.is_null() {
return Ok(None);
}
T::try_from_value(value).map(Some)
}
}
Currently, we first try to decode the value normally. If decoding fails (because it's null), an error is created. For
Option<T>, we then drop that error and returnNoneinstead. This means decoding an optional value still constructs an error string on the failure path, which adds unnecessary allocation and overhead.Ideally, we should provide a blanket implementation for
Option<T>. Then users would only need to implement the conversion from our value for their own types.This is a breaking change because it requires users to rewrite all their implementation to add the new method.
Example: