I believe you need to specify, when declaring foo_generic, that your type T has
the Ord trait (i.e. that objects of type T can be ordered, which is necessary
in order for them to be sorted.) I think the way to do that is
fn foo_generic<T: Ord>...
When I test this, I have to 'use cmp::Ord;' in order to get Ord in scope. Then
I get a similar error about the Eq trait, but I have not yet figured out how to
convince rust that my type T also has Eq. The seemingly-obvious thing of "T:
Ord, Eq", combined with 'use cmp::Eq;' does not work.
/tmp/foo.rs:8:4: 8:15 error: failed to find an implementation of trait
core::cmp::Eq for <V6>
/tmp/foo.rs:8 quick_sort3(part);
(Although the error spells it core::cmp::Eq, using that doesn't help.)
Note that I am using rustc 0.5 -- I think the syntax for this may have changed
since then, confusing things further.
Glenn
On Feb 2, 2013, at 10:36 PM, Alexander Stavonin wrote:
> Hi,
>
> I'm not sure it is an defect or failure to fully understand from my side. I'd
> like to sort an array. Unfortunately, it is not easy to understand which sort
> function should be used, but looks like quick_sort3 is good enough.
>
> Than:
>
> 1 extern mod std;
> 2 use std::sort::*;
> 3
> 4 fn foo_generic<T>(data : &[T]) {
> 5 let part = data.slice(0, data.len()/2);
> 6 quick_sort3(part);
>
> 7 io::println(part.to_str());
> 8 }
> 9
> 10 fn foo(data : &[int]) {
> 11 let mut part = data.slice(0, data.len()/2);
> 12 quick_sort3(part);
> 13 io::println(part.to_str());
> 14 }
> 15 fn main() {
> 16 let data = ~[1, 3, 5, 2, 4, 6];
> 17 foo(data);
> 18 foo_generic(data);
> 19 }
>
>
> test.rs:6:4: 6:15 error: failed to find an implementation of trait
> @core::cmp::Ord for <V13>
> test.rs:6 quick_sort3(part);
> ^~~~~~~~~~~
>
> Is the foo_generic correct function?
>
> Regards,
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
> !DSPAM:510e0ce6261275098973934!
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev