-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Generic type alias: unable to access static fn #5635
Comments
Well, it seems a regular type alias doesn't either:
fails with
No idea what the intended behavior is there. |
I believe this is intended behavior. My work-around is to create a wrapper. Eg: impl Bar {
#[inline(always)]
pub fn new(t: float) -> Bar { Foo::new(t) }
} This could then be turned into a macro. I'm thinking something like this in my own library: macro_rules! vec2_type(
($name:ident < $T:ty >) => (
type $name = Vec2<$T>;
impl $name {
wrap_fn!(Vector2::new(x: $T ,y: $T) -> $name)
wrap_fn!(Vector::from_value(v: $T) -> $name)
wrap_fn!(NumericVector::identity() -> $name)
wrap_fn!(NumericVector::zero() -> $name)
wrap_fn!(NumericVector2::unit_x() -> $name)
wrap_fn!(NumericVector2::unit_y() -> $name)
wrap_fn!(dim() -> uint { 2 })
wrap_fn!(size_of() -> uint { size_of::<$name>() })
}
)
)
pub vec2_type!(vec2<f32>)
pub vec2_type!(dvec2<f64>)
pub vec2_type!(ivec2<i32>)
pub vec2_type!(uvec2<u32>) Unfortunately you then run into lots of unfixed macro issues, like #4375 and #4621. Edit: I've now half-implemented the wrapper impl macro. I can't complete it because of #4375, but all in good time. :) |
@bjz Do you happen to know why this intended? |
Type aliases don't work this way -- a type alias defines a name in the type namespace. The thing before |
Couldn't/shouldn't a type alias also define a module in the module namespace when the type that is being aliased corresponds to a module containing static methods from an |
…e, r=flip1995 option_option test case rust-lang#4298 Adds regression test case for rust-lang#4298. The bug seems still present although rust Playground said otherwise. changelog: none
It seems a generic type alias does not carry over static function. (incoming as of 03-29-13)
The text was updated successfully, but these errors were encountered: