Apparently this works as well:

let t = Test::<bool>::new().test();
println!("t={}", t);

On 2014-06-04, at 10:50, Tommi <rusty.ga...@icloud.com> wrote:

> I don't know if there's a better way, but this at least works:
> 
> let tmp: Test<bool> = Test::new();
> let t = tmp.test();
> println!("t={}", t);
> 
> On 2014-06-04, at 10:28, Igor Bukanov <i...@mir2.org> wrote:
> 
>> What is the syntax for calling a static method of a generic struct
>> while selecting the the generic parameters explicitly? Apparently
>> Struct<Type>::static_method does not work. For example, consider the
>> following program:
>> 
>> #[deriving(Show)]
>> struct Test<T> { i: int }
>> 
>> impl<T> Test<T> {
>>    fn new() -> Test<T> { Test {i: 1} }
>>    fn test(&self) -> int { self.i }
>> }
>> 
>> fn main() {
>>    let t = Test<bool>::new().test();
>>    println!("t={}", t);
>> }
>> 
>> The latest nightly compiler generates:
>> 
>> s.rs:10:13: 10:17 error: `Test` is a structure name, but this
>> expression uses it like a function name
>> s.rs:10     let t = Test<bool>::new().test();
>>                    ^~~~
>> 
>> Note that in this case type inference does not work as removing <bool> gives:
>> 
>> s.rs:10:13: 10:31 error: cannot determine a type for this expression:
>> unconstrained type
>> s.rs:10     let t = Test::new().test();
>>                    ^~~~~~~~~~~~~~~~~~
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
> 

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to