-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate Param
/Ref
/InterfaceRef
etc
#3233
Comments
Param
/Ref
/InterfaceRef
Param
/Ref
/InterfaceRef
etc
We should try and use Particularly, the difference in the closure signature between |
Ideally we could have an pub trait AsRef<T> where T: Type<T> {
fn as_ref<'a>(&'a self) -> Ref<'a, T>;
}
impl<T: Type<T>> AsRef<T> for T {
fn as_ref<'a>(&'a self) -> Ref<'a, T> {
unsafe { transmute_copy(self) }
}
}
impl<'a, T: Type<T>> AsRef<T> for &'a T {
fn as_ref(&self) -> Ref<'a, T> {
unsafe { transmute_copy(self) }
}
}
impl<'a, T: Type<T>> AsRef<T> for Option<&'a T> {
fn as_ref(&self) -> Ref<'a, T> {
unsafe {
match self {
Some(value) => transmute_copy(value),
None => Ref::zeroed(),
}
}
}
} This would then provide more uniform parameter binding across regular and generic parameters and be far simpler in general. As noted in #3394 this doesn't support polymorphism the way that |
A number of conversion types and traits have been developed to solve different problems. Some like
Param
are used bywindows-bindgen
while others are more suitable for hand-authored APIs. It's just a bit confusing and hard to know what the right tool is where there are so many options.The text was updated successfully, but these errors were encountered: