[rust-dev] TotalOrd and cmp::max

2014-04-05 Thread Rémi Fontan
Hi, when compiling following code with rust 0.10 I get following error: use std::cmp; struct vec2d { a:f32, b:f32 } impl vec2d { pub fn max(self) - f32 { cmp::max(self.a, self.b) } } test.rs:6:9: 6:17 error: failed to find an implementation of trait std::cmp::TotalOrd for f32

Re: [rust-dev] Building a static array of pointers

2014-04-05 Thread Corey Richardson
A C-style array is written `*T`, much like in C (note: I'm not saying `T*` and `T[]` are the same type, I know they aren't) On Sat, Apr 5, 2014 at 6:53 AM, Simon Sapin simon.sa...@exyr.org wrote: On 05/04/2014 11:39, Vladimir Pouzanov wrote: The problem is that [extern unsafe fn()] results in

Re: [rust-dev] Building a static array of pointers

2014-04-05 Thread Vladimir Pouzanov
Ended up specifying array size as per Simon's suggestion: #[link_section=.isr_vector_temp] #[no_mangle] pub static ISRVectors: [extern unsafe fn(), ..4] = [ _stack_base, main, isr_nmi, isr_hardfault, ]; Given that table size is an architecture-dependent time constant, it also adds a tiny

Re: [rust-dev] Building a static array of pointers

2014-04-05 Thread Simon Sapin
On 05/04/2014 12:00, Corey Richardson wrote: A C-style array is written `*T`, much like in C (note: I'm not saying `T*` and `T[]` are the same type, I know they aren't) *T in Rust is not an array, it is a raw pointer. It may happen to point to the start of an array that you could unsafely

Re: [rust-dev] Building a static array of pointers

2014-04-05 Thread Simon Sapin
On 05/04/2014 13:28, Vladimir Pouzanov wrote: Also tried defining something along the lines of *[extern unsafe fn()], but I guess size is also required in this case. This will probably work once we have DST, but it will result in a fixed-size pointer to an array, rather than the actual array

Re: [rust-dev] Building a static array of pointers

2014-04-05 Thread Daniel Micay
On 05/04/14 09:23 AM, Simon Sapin wrote: On 05/04/2014 14:14, Corey Richardson wrote: Sure, same thing as a C-style array, minus the fact that we don't have Index implemented for unsafe ptrs. Sure, but that difference is the important part. It’s idiomatic C to pretend that a pointer is like

[rust-dev] Is it possible to implement extension methods on existing traits?

2014-04-05 Thread Frank Huang
Hello everyone, I have a question about making extension methods on something like io::Writer. Basically, I have a data format that requires strings to be serialized as an 8-byte length header and then the string bytes themselves. Instead of having to type writer.write_u64(...);

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-05 Thread Rodrigo Rivas
On Fri, Apr 4, 2014 at 10:41 PM, Philippe Delrieu philippe.delr...@free.fr wrote: Hello, I've some problem to find a solution for something I want to do with a vector of enum. This is an example of what I want to do: trait Base{ fn set_something(mut self); } struct FirstThink;

Re: [rust-dev] Is it possible to implement extension methods on existing traits?

2014-04-05 Thread Steven Fackler
You can do it like this: implT: Writer MySerialization for T { ... } Steven Fackler On Sat, Apr 5, 2014 at 12:57 PM, Frank Huang m...@nongraphical.com wrote: Hello everyone, I have a question about making extension methods on something like io::Writer. Basically, I have a data format

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-05 Thread Philippe Delrieu
Very good idea. The vector don't have to be modified so it'll work. Thank you for the advice. I make a try an I'll post the result. Philippe Le 05/04/2014 21:59, Rodrigo Rivas a écrit : On Fri, Apr 4, 2014 at 10:41 PM, Philippe Delrieu philippe.delr...@free.fr wrote: Hello, I've some

Re: [rust-dev] Is it possible to implement extension methods on existing traits?

2014-04-05 Thread Frank Huang
Thanks for the quick response, Steven! Having done what you suggested, I'm now getting the following error (for serializing a larger struct in which some fields are strings): implT: Writer MySerialization for T { fn write_my_string(mut self, s: str) - IoResult() { ... } } impl

Re: [rust-dev] Is it possible to implement extension methods on existing traits?

2014-04-05 Thread Sean McArthur
I can't say why the immutable argument error is happening, but there's another error in that function. You're using a `Writer`, but Writer doesn't have `write_my_string`, only `MySerialization` does. I'd write that like this: fn save_toT: MySerialization(self, writer: mut T) - io::IoResult() {

Re: [rust-dev] Is it possible to implement extension methods on existing traits?

2014-04-05 Thread Patrick Walton
Try this: On 4/5/14 1:55 PM, Frank Huang wrote: implT: Writer MySerialization for T { fn write_my_string(mut self, s: str) - IoResult() { ... } } impl StructToBeSerialized { fn save_to(self, mut writer: mut io::Writer) - io::IoResult() {