-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
I'm writing a function use match_type to improve performance, the main idea looks like this
trait MyConvert {
type Raw: 'static;
fn into_raw(self) -> Self::Raw;
fn into_f64(self) -> f64;
fn into_i64(self) -> i64 {
match_type!(self.into_raw(), {
i64 as a => return a,
i32 as a => return a as i64,
i128 as a => return a as i64,
_ => {},
});
self.into_f64() as i64
}
}The into_raw and into_f64 are required method in trait.
Now this code couldn't compile without Self: Copy, shall we improve it like this
match_type!(self.into_raw(): Self::Raw, {
i64 as a => return a,
i32 as a => return a as i64,
i128 as a => return a as i64
}and check CastToken::<Self::Raw>::of() == CastToken::<i32>::of() first before self.into_raw(), so that self wouldn't be consumed in unmatched arms.
We could keep both 2 usages:
- if explicit type exists, we do the lazy evaluation,
- when it presence, keep it as is.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels