My aim is to create a custom unwrap option function that works on any type which implements the default trait and in the case the type has no data (none) it returns the default for that type. Here is my attempt:
fn unwrap_option(data: Option<T>) -> T
where T: Default
{
if(data.is_none()){
return T::default();
}
else{
return string.unwrap();
}
}
But it doesn't work.
Option::unwrap_or_default
? – mcartonfn unwrap_option<T>(...
) and fixed what I assume to be a typo, changingstring.unwrap()
todata.unwrap()
. – Benjamin Lindley