[rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread spir
Hello, New to Rust. Is there (already) a list for mutual help in the usage of Rust? If not, I guess it may be worth having one, distinct from the dev list, even if the language is a moving target, even for people who rather intend, at terms, to participate in the development. It is in fact

Re: [rust-dev] Abandoning segmented stacks in Rust

2013-11-05 Thread Tiffany Bennett
If you really need such a small memory footprint for your tasks, I am of the opinion that it would be less error prone (whoops, accidentally used 64 bytes of stack than I should have, now I'm using twice as much memory!) to use an async event loop, like libevent, rather than a task model. It just

Re: [rust-dev] Abandoning segmented stacks in Rust

2013-11-05 Thread David Piepgrass
Segmented stacks aren't the only solution though. If the concern is many tasks that block for a long time, I imagine a mechanism to bundle a bunch of small, dormant stacks into a single page so that the original pages could be released to the OS. If stacks were additionally relocatable (which

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread Patrick Walton
On 11/5/13 2:44 AM, spir wrote: Why not just add a declaration of the trait at the top of the struct type def? struct PairListVal : Iterable { You can implement traits on types that aren't structs. * either the methods inside the struct def: struct PairListVal { fn push (self, key:Key,

Re: [rust-dev] Abandoning segmented stacks in Rust

2013-11-05 Thread Patrick Walton
On 11/5/13 8:32 AM, David Piepgrass wrote: Segmented stacks aren't the only solution though. If the concern is many tasks that block for a long time, I imagine a mechanism to bundle a bunch of small, dormant stacks into a single page so that the original pages could be released to the OS. If

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread spir
On 11/05/2013 06:17 PM, Patrick Walton wrote: On 11/5/13 2:44 AM, spir wrote: That you very much for this complete answer, Patrick. Things are clearer. Denis ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread Ziad Hatahet
On Tue, Nov 5, 2013 at 9:17 AM, Patrick Walton pcwal...@mozilla.com wrote: On 11/5/13 2:44 AM, spir wrote: Why not just add a declaration of the trait at the top of the struct type def? struct PairListVal : Iterable { You can implement traits on types that aren't structs. Isn't

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread Steven Blenkinsop
As long as you are the person who owns the type, yeah, but I suspect that's not what you mean. Coherence requires that you only implement traits for types if you own either the trait or the type (or both). You can't implement a 3rd party trait for a 3rd party type, since then there could be

Re: [rust-dev] Abandoning segmented stacks in Rust

2013-11-05 Thread Brian Anderson
On 11/04/2013 07:50 PM, Bill Myers wrote: The advantage of segmented stacks is that blocked tasks only take up as much memory as they actually need to store state, so that for instance a network server can use a task for each connection, and still only use, say, 64 bytes per connection if

Re: [rust-dev] Abandoning segmented stacks in Rust

2013-11-05 Thread Haoyi Li
C# Async/Await is distinct from segmented stacks because they store the enclosed variables as heap objects rather than on the stack; that means it goes through the same malloc/garbage collector as any other heap objects you create. It's purely a compiler fiction to let you write code that 'looks'

Re: [rust-dev] Abandoning segmented stacks in Rust

2013-11-05 Thread Corey Richardson
On Tue, Nov 5, 2013 at 4:40 PM, Brian Anderson bander...@mozilla.com wrote: On 11/04/2013 07:50 PM, Bill Myers wrote: The advantage of segmented stacks is that blocked tasks only take up as much memory as they actually need to store state, so that for instance a network server can use a task

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread Ziad Hatahet
The following seems to work: trait Double { fn double(self) - Self; } impl Double for int { fn double(self) - int { *self * 2 } } fn main() { let x = 2; println!({}, x.double()); // prints 4 } -- Ziad On Tue, Nov 5, 2013 at 1:29 PM, Steven Blenkinsop

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread Steven Blenkinsop
Here you own the trait Double. Doesn't work if you were trying to implement a trait you hadn't just defined. The specific examples you mentioned were Clone and Drop, so that wouldn't work. On Tuesday, November 5, 2013, Ziad Hatahet wrote: The following seems to work: trait Double { fn

Re: [rust-dev] the inter-play of struct type impl, traits, type params

2013-11-05 Thread Ziad Hatahet
Gotcha. But it is still pretty flexible in that you are not bound to the impls that were originally defined on the type (e.g. like C++/Java where the list of interfaces implemented by a class are fixed). This relieves one form writing wrapper classes in order for certain structs to adhere to

[rust-dev] struct def

2013-11-05 Thread spir
I can write this: struct Points {xs:~[uint], ys:~[uint]} fn main () { let mut ps = Points{xs:~[1u], ys:~[1u]}; ... } But I cannot write that: struct PointsT {xs:~[T], ys:~[T]} fn main () { let mut ps = Pointsuint{xs:~[1u], ys:~[1u]}; ... } In