Re: [rust-dev] Error: cannot borrow `***test` as mutable because it is also borrowed as immutable in match

2014-04-28 Thread Philippe Delrieu

Hello,

I've updated my sample code to reflect what I'll do in my main program. 
I put it back on the list because it can help as a pattern to manage a 
tree of polymorph object.

It compile and works.
I have some question too because I'm not sure I've done it the right way:
   * I cross the tree recursively and return Option in each call. To 
manage recursion I put the call in a match and end with this sort of 
boilerplate code:

match obj.call_fn_recusive(){
Some(ret) = {return Some(ret);},
None = {},
}
Is there a way to avoid this line: Some(ret) = {return 
Some(ret);},
  * It's very hard to manage reference and borrowing of object. I spend 
some time to make it compile and change my algorithm several time. 
That's why I think examples and patterns can be very useful because you 
can't do what you want in rust. In other works there is no easy 
shortcut, you have to find the right way.
 * closure indentation. Is there a good way to indent closure in 
function call to make it readable easily. It's very hard to find the 
begin/end of the closure code from the function and match call (see code).


Some world about the pattern :
I use an enum to define a type that manage all my polymorph object (enum 
UINode). It's the simplest way I found to have a collection a different 
objects that implement part of the same trait. I don't want to use 
unsafe code and low memory management. Perhaps there is a better pattern.
The object can only be retrieve or modified with search function that 
use a closure to do the job. It's work well to avoid to know how the 
tree is organized and to avoid object reference outside the tree.  The 
mutable part is restricted to one function too.


The code:

use std::vec::Vec;

pub enum UINode {
DrawableNode(Inside),
ContainerNode(ListInside),
}

//common trait for all object
trait Component {
fn get_width(self) - uint;
fn get_id(self) - uint;
}

//first struct. derive clone because it can be return as a copy.
//base component.
#[deriving(Clone)]
pub struct Inside {
id: uint,
width: uint,
}

impl Component for Inside{
fn get_id(self) - uint {self.id}
fn get_width(self) - uint {
self.width
}
}

//the container that is a component and a container of components.
pub struct ListInside   {
id: uint,
width: uint,
list: Vec~UINode,
}


impl Component for ListInside{
fn get_id(self) - uint {self.id}
fn get_width(self)  - uint  {
self.width
}
}

//some container function and the search and modify function.
impl ListInside {
fn addInside(mut self, inside: Inside)   {
self.list.push(~DrawableNode(inside));
}

fn addList(mut self, list: ListInside)   {
self.list.push(~ContainerNode(list));
}

// search for a UINode using the closure filter to find the right. 
Return the node Id.
fn match_fn'a('a self, filter: 'a |'a UINode| - Optionuint) 
-Optionuint {

for inside in self.list.iter(){
match (*filter)(*inside){
Some(found) = return Some(found),
None = {},
};
//try on sub tree
match **inside{
DrawableNode(_) = {},
ContainerNode(ref list_inside) = {
match list_inside.match_fn(filter)  {
Some(ret) = {return Some(ret);}
None = {}
}
},
}
}
None
}

//modify using the specified closure the Component with specified id.
fn test_mutable'a('a mut self, id: uint, update: 'a|'a mut 
Inside|) {

for node in self.list.mut_iter()   {
match **node{
DrawableNode(ref mut inside) = {if inside.get_id() == 
id {(*update)(inside)}},
ContainerNode(ref mut list_inside) = 
list_inside.test_mutable(id, update),

}
}
}

//return a copy of the Component with specified id. Doesn't return 
container, only Inside.

fn search_node'a('a self, id: uint) - Option~Component {
for node in self.list.iter()   {
match **node{
DrawableNode(ref inside) = if inside.get_id() == id { 
return Some((~inside.clone()) as ~Component);},
ContainerNode(ref list_inside) = { match 
list_inside.search_node(id)   {

Some(elem) = {return Some(elem);},
None = {},
}},
}
}
None
}
}

fn TestTreeSearchModify(){
let mut list_inside = ListInside{
id: 0,
width: 10,
list: Vec::new(),
};

let mut list2 = ListInside{
id: 3,
width: 30,
list: Vec::new(),
};

let inside1 = Inside {
id: 1,
width: 21,
};

let inside2 = Inside {
id: 2,
width: 22,
};

list_inside.addInside(inside1);

Re: [rust-dev] Error: cannot borrow `***test` as mutable because it is also borrowed as immutable in match

2014-04-27 Thread Philippe Delrieu
I try to implement a sort of zoom UI. The UI components are organized in 
a tree. To update a component in the UI I use a search function 
(match_fn() in the example) which take a closure as search criteria and 
if it returns something I use an update function (test_mutable) with a 
closure to do the update part. The update part only need an Id and the 
closure. So returning the found component is not mandatory. If the 
search function return only a copy of the component id it solves the 
borrow error but I would like to have the found component.


I return a reference (Option'a Inside) to avoid object copy. A 
component can have a large sub tree. If I change and return a copy in 
the search function (OptionInside) It works. Logic the Inside life 
time start at the Some level (as I understand).


Perhaps you'll have a better idea to do this. I use this pattern (search 
and update function) for this reasons:

   * no multiple owned objects. All object are only owned in the tree.
   * maintain most immutability

I put a new version of the test code nearer to my main code.


use std::vec::Vec;
use std::task;

pub enum UINode {
DrawableNode(Container),
ContainerNode(Inside),
}

struct Inside {
layout: fn(Inside) - uint,
}

impl Inside {
fn get_id(self) - uint {1}
}

trait Trait {}

struct ListInside   {
tt: ~Trait: Send,
list: Vec~UINode,
}

struct Container{
inside:~ListInside,
}

impl ListInside {
fn match_fn'a('a self, filter: 'a |'a UINode| - Option'a 
Inside) -Option'a Inside {

for inside in self.list.iter(){
match (*filter)(*inside){
Some(found) = return Some(found),
None = {},
};
}
None
}

fn test_mutable'a('a mut self, id: uint, update: 'a|component: 
'a mut Inside|) {}

}

fn TestMatchBorrow(){
let task = task::task();
task.spawn (proc()  {

let mut viewList: Vec~Container = Vec::new();

for ref mut container in viewList.mut_iter(){
//let mut my_var = mut *(container.inside);
match container.inside.match_fn(|inside: UINode| - 
OptionInside {None})   {
Some(inside) = 
container.inside.test_mutable(inside.get_id(), |component: mut Inside| 
{}),

None = {},
}
}
});

}

#[main]
fn main() {
TestMatchBorrow();
}

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


Re: [rust-dev] Error: cannot borrow `***test` as mutable because it is also borrowed as immutable in match

2014-04-25 Thread Philippe Delrieu

Thanks for your help. It works on the test but not in my main program.

I'll try to update the test to make it works like the main program but I 
have not yet found what make the base code different.


Philippe

Le 24/04/2014 23:06, Artella Coding a écrit :
Hi, the following modified program seems to work (I am using rustc 
0.11-pre-nightly (d35804e 2014-04-18 00:01:22 -0700) :



**
use std::vec::Vec;
use std::rc::Rc;
use std::cell::RefCell;

struct Test;

impl Test {
 fn match_fn'a('a self) -Option'a Test {
 None
 }

 fn test_mutable'a('a mut self, test: 'a mut Test) {}
}

fn TestMatchBorrow(){
 let mut viewList: Vec~Test = Vec::new();

 for ref mut test in viewList.mut_iter(){
 match test.match_fn()   {
Some(mut borrow_test) = test.test_mutable(mut borrow_test),
None = {},
 }
 }

}

#[main]
fn main() {
 TestMatchBorrow();
}
**



On Thu, Apr 24, 2014 at 9:23 PM, Philippe Delrieu 
philippe.delr...@free.fr mailto:philippe.delr...@free.fr wrote:


Hello,

I have a problem in my code and I can't find a solution. I develop
a test case that generate the same error. Any idea?

use std::vec::Vec;
use std::rc::Rc;
use std::cell::RefCell;

struct Test;

impl Test {
fn match_fn'a('a self) -Option'a Test {
None
}

fn test_mutable'a('a mut self, test: 'a Test) {}
}

fn TestMatchBorrow(){
let mut viewList: Vec~Test = Vec::new();

for ref mut test in viewList.mut_iter(){
match test.match_fn()   {
Some(mut borrow_test) = test.test_mutable(borrow_test),
None = {},
}
}

}

#[main]
fn main() {
TestMatchBorrow();
}

The test struct can't be changed.
If I don't put the borrow_test in test.test_mutable(borrow_test)
it compile.

The error :
test_match.rs:22:38: 22:42 error: cannot borrow `***test` as
mutable because it is also borrowed as immutable
test_match.rs:22 http://test_match.rs:22 Some(mut
borrow_test) = test.test_mutable(borrow_test),
^~~~
test_match.rs:21:15: 21:19 note: previous borrow of `***test`
occurs here; the immutable borrow prevents subsequent moves or
mutable borrows of `***test` until the borrow ends
test_match.rs:21 http://test_match.rs:21 match
test.match_fn()   {
^~~~
test_match.rs:24:10: 24:10 note: previous borrow ends here
test_match.rs:21 http://test_match.rs:21 match
test.match_fn()   {
test_match.rs:22 http://test_match.rs:22 Some(mut
borrow_test) = test.test_mutable(borrow_test),
test_match.rs:23 http://test_match.rs:23 None = {},
test_match.rs:24 http://test_match.rs:24 }

Philippe
___
Rust-dev mailing list
Rust-dev@mozilla.org mailto: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


[rust-dev] Error: cannot borrow `***test` as mutable because it is also borrowed as immutable in match

2014-04-24 Thread Philippe Delrieu

Hello,

I have a problem in my code and I can't find a solution. I develop a 
test case that generate the same error. Any idea?


use std::vec::Vec;
use std::rc::Rc;
use std::cell::RefCell;

struct Test;

impl Test {
fn match_fn'a('a self) -Option'a Test {
None
}

fn test_mutable'a('a mut self, test: 'a Test) {}
}

fn TestMatchBorrow(){
let mut viewList: Vec~Test = Vec::new();

for ref mut test in viewList.mut_iter(){
match test.match_fn()   {
Some(mut borrow_test) = test.test_mutable(borrow_test),
None = {},
}
}

}

#[main]
fn main() {
TestMatchBorrow();
}

The test struct can't be changed.
If I don't put the borrow_test in test.test_mutable(borrow_test) it compile.

The error :
test_match.rs:22:38: 22:42 error: cannot borrow `***test` as mutable 
because it is also borrowed as immutable
test_match.rs:22 Some(mut borrow_test) = 
test.test_mutable(borrow_test),

^~~~
test_match.rs:21:15: 21:19 note: previous borrow of `***test` occurs 
here; the immutable borrow prevents subsequent moves or mutable borrows 
of `***test` until the borrow ends

test_match.rs:21 match test.match_fn()   {
^~~~
test_match.rs:24:10: 24:10 note: previous borrow ends here
test_match.rs:21 match test.match_fn()   {
test_match.rs:22 Some(mut borrow_test) = 
test.test_mutable(borrow_test),

test_match.rs:23 None = {},
test_match.rs:24 }

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


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

2014-04-10 Thread Philippe Delrieu
I trying to do some polymorphism with trait and object and I have some 
problems.


At the beginning I want to store different types of object that 
implement the same trait (Base) in a Vec. To do this I use the enum 
pattern. If the enum contains only struct, I manage to iter the Vec for 
the different types.

code:
enum BaseImpl{
FirstThinkImpl(FirstThink),
SecondThinkImpl(SecondThink),
}

What I would like to do is to have a generic method to add like 
addMyBaseTrait( ~Base) to add all the struct that implement Base to the 
vector and to have a specific method that add a specific struct 
addSecondStruct(~SecondStruct). The enum is changed to:

enum BaseImpl{
FirstThinkImpl(~Base),
SecondThinkImpl(~SecondThink),
}

With this enum has have problem to iter the vector. I didn't find a way 
to iter all the vector and return Base or ~Base:

this code
impl'a Iterator'a ~Base for BaseItems'a {
fn next(mut self) - Option'a ~Base{
match self.iter.next() {
Some(ref baseimpl) = {
Some(match ***baseimpl{
FirstThinkImpl(ref first) = first,
SecondThinkImpl(ref second)= 'a (*second as ~Base),
})
},
None = None,
}
}
}
generate an error  borrowed value does not live long enough 
SecondThinkImpl(ref second)= 'a (*second as ~Base), which is logic so 
I try not to borrow with this code:


SecondThinkImpl(ref second)= second as 'a ~Base,

and I have the error non-scalar cast: `~SecondThink` as `'a 
~Baseno-bounds`

Perhaps there is no way. I didn't find any.
What I see with all my test is that a trait must be use as a reference 
to be stored but object reference can't be cast to a reference trait and 
trait can't be cast to an object. So it seems that tray is useful to 
pass or return parameters to method but not to store data.


Philippe


Le 09/04/2014 21:53, Philippe Delrieu a écrit :

I find a solution by removing the ~ to Base trait.
The code

//(First and Second think as defined earlier)


enum BaseImpl{
FirstThinkImpl(FirstThink),
SecondThinkImpl(SecondThink),
}


struct Container{
nodeList: Vec~BaseImpl,
}

impl'a Container{

fn iter_base('a self) - BaseItems'a {
   let iter = self.nodeList.iter();
   BaseItems{ iter : iter }
}

}


struct BaseItems'a {
iter : Items'a, ~BaseImpl
}

impl'a Iterator'a Base for BaseItems'a {
fn next(mut self) - Option'a Base{
match self.iter.next() {
Some(ref baseimpl) = {
Some(match ***baseimpl{
FirstThinkImpl(ref first) = first as 'a Base,
SecondThinkImpl(ref second)= second as 'a Base,
})
},
None = None,
}
}
}

Now it compile.

So I try to define a mutable iterator like the immuable and with 
similar code I have again the lifetime compile error :



struct BaseMutItems'a {
iter : MutItems'a, ~BaseImpl
}

impl'a Iterator'a mut Base for BaseMutItems'a {
fn next(mut self) - Option'a mut Base {
match self.iter.next() {
Some(ref mut baseimpl) = {
Some(match ***baseimpl{
FirstThinkImpl(ref mut first) = first as 'a mut 
Base,
SecondThinkImpl(ref mut second)= second as 'a 
mut Base,

})
},
None = None,
}
}
}

error :
test_enum.rs:125:36: 125:49 error: lifetime of `baseimpl` is too short 
to guarantee its contents can be safely reborrowed
test_enum.rs:125 FirstThinkImpl(ref mut first) = 
first as 'a mut Base,


I can't see what's going wrong.


I put all the code if someone want to test :

use std::iter::Iterator;
use std::slice::{Items, MutItems};

trait Base{
  fn set_something(mut self);
  fn isSecondThink(self) - bool;
}

struct FirstThink{
count1: int,
}

impl Base for FirstThink{
fn set_something(mut self){println!(ici First count:{:?}, 
self.count1); self.count1+=1;}

fn isSecondThink(self) - bool  {false}
}

struct SecondThink{
count2: int,
}

impl Base for SecondThink{
fn set_something(mut self){println!(ici Second count:{:?}, 
self.count2); self.count2+=1;}

fn isSecondThink(self) - bool  {true}
}

enum BaseImpl{
FirstThinkImpl(FirstThink),
SecondThinkImpl(SecondThink),
}

fn some_second_process(think: mut SecondThink){
think.set_something();
}

struct Container{
nodeList: Vec~BaseImpl,
}

impl'a Container{
fn add_FirstThink(mut self, think: FirstThink){
self.nodeList.push(~FirstThinkImpl(think));
}
fn add_SecondThink(mut self, think: SecondThink){
self.nodeList.push(~SecondThinkImpl(think));
}


fn iter_base('a self) - BaseItems'a {
   let iter = self.nodeList.iter();
   BaseItems{ iter : iter }
}

fn iter_second('a self) - SecondItems'a

[rust-dev] does not fulfill `Send` error since last pull request

2014-04-10 Thread Philippe Delrieu

Since my last today gill fetch I have this error:

error: instantiating a type parameter with an incompatible type 
`~BaseImpl`, which does not fulfill `Send`


for this code :
trait Base{}

struct SecondThink{
count2: int,
}

enum BaseImpl{
FirstThinkImpl(~Base),
SecondThinkImpl(~SecondThink),
}

let (newchan, newport): (SenderBaseImpl, ReceiverBaseImpl) = 
channel();  -- error here

^~~
The Send behavior has changed? Is it permanent and if yes is there a 
work around?


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


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

2014-04-09 Thread Philippe Delrieu
]
fn main() {
let first = FirstThink{count1:0};
let second = SecondThink{count2:0};

let mut container = Container{nodeList: Vec::new()};
container.add_FirstThink(first);
container.add_SecondThink(second);
container.appli_secondthink_someprocess(some_second_process);
container.appli_secondthink_someprocess(some_second_process);
for think in container.iter_base(){
println!(ici Second count:{:?}, think.isSecondThink());
}

for think in container.iter_second(){
println!(ici Second count:{:?}, think.isSecondThink());
}
container.appli_secondthink_someprocess(some_second_process);
}

Le 07/04/2014 13:17, Philippe Delrieu a écrit :

I try to implement the iterator like that:


struct BaseItems'a {
iter : Items'a, ~BaseImpl
}

impl'a Iterator'a ~Base for BaseItems'a {
fn next(mut self) - Option'a ~Base{
match self.iter.next() {
Some(ref baseimpl) = {
Some('a match ***baseimpl{
FirstThinkImpl(ref first) = *first as ~Base,
SecondThinkImpl(ref second)= *second as ~Base,
})
},
None = None,
}
}
}

But I have a lifetime problem. The error is : borrowed value does not 
live long enough and reference must be valid for the lifetime 'a  as 
defined on the block

and :
cannot move out of dereference of ``-pointer SecondThinkImpl(ref 
second)= *second as ~Base,


Another possibility:
fn next(mut self) - Option'a ~Base{
match self.iter.next() {
Some(ref baseimpl) = {
Some(match ***baseimpl{
FirstThinkImpl(ref first) = first as 'a ~Base,
SecondThinkImpl(ref second)= second as 'a 
~Base,

})
},
None = None,
}
}
generate the error: non-scalar cast: `~FirstThink` as `'a 
~Baseno-bounds`


I try different possibility but I didn't find how to return a 'a 
lifetime ~Base or Base


I remove the mut to simplify the test of the different lifetime 
possibilities.


Philippe

Le 07/04/2014 10:27, Rodrigo Rivas a écrit :

On Sun, Apr 6, 2014 at 7:50 PM, Philippe Delrieu
philippe.delr...@free.fr wrote:

I need some more help.

The impl Iteratormut  ~Base for Container declaration generate 
the error:

error: missing lifetime specifier
So I had it but I can't manage to return the next value with the 
specified

life time.
The code :
impl'a Iterator'a mut  ~Base for Container {
 /// Advance the iterator and return the next value. Return 
`None` when

the end is reached.
 fn next(mut self) - Option'a mut ~Base{
 if self.iter_counter == self.nodeList.len()   {
 None
 } else  {
 self.iter_counter += 1;
 Some('a mut match **self.nodeList.get(self.iter_counter){
 FirstThinkImpl(first) = first as ~Base,
 SecondThinkImpl(second)= second as ~Base,
 })
 }
 }
}

Generate these errors :
test_enum.rs:58:18: 61:14 error: borrowed value does not live long 
enough

test/test_enum.rs:58 Some('a mut match

Oh, I think I may have misleaded you... You cannot implement the
iterator directly in Container, because the iterator must handle the
current position, while the Container just holds the values. You need
a intermediate struct that implements the Iterator traits. That's what
the `iter()` and ' move_iter()` functions do for vectors and other
standard containers. So you'll need something along the lines of this
(disclaimer: totally untested!!):

struct Container {
 //
 fn iter('a self) - BaseItems'a {
let iter = nodeList.iter();
BaseItems{ iter : iter }
 }
}

struct BaseItems'a {
 iter : Items'a, ~Base
}

impl'a Iterator'a mut  ~Base for BaseItems'a {
 //
}

BTW, why all the double pointer in all the mut ~Base instead of
just mut Base?



___
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


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

2014-04-07 Thread Philippe Delrieu

Thanks for your help. I'll test ASAP.
I use the counter mutable var to have a simple implantation of the 
iterator to make the code works. Thank for you're example to show a 
better way. I was thinking of a similar way but I would like to avoid 
the specific struct with perhaps use a recursive call. I'll think about 
it later.


Le 07/04/2014 10:27, Rodrigo Rivas a écrit :

BTW, why all the double pointer in all the mut ~Base instead of
just mut Base?
For your question, I have mut ~Base because i didn't find a way to 
convert the mut ~Base to mut Base (or ~Base to Base) without copy.
I have the error error: mismatched types: expected 
`std::option::Option'a mut ~Baseno-bounds` but found 
`std::option::Optionmut ~Baseno-bounds`
I try  (error above), * error type `~Baseno-bounds` cannot be 
dereferenced. So I stop searching and try to make it works with ~Base.
The callback function is modifying the Vec instance. It's a method that 
update all the of the Vec element after an event occurs. I have to keep 
the reference to the Vec instance during the call. Perhaps there's a 
conception problem that I'll look later to remove most of the mut call 
but I try this type of call to learn who Rust works.


Perhaps you can help me for this part.

Philippe

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


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

2014-04-07 Thread Philippe Delrieu

I try to implement the iterator like that:


struct BaseItems'a {
iter : Items'a, ~BaseImpl
}

impl'a Iterator'a ~Base for BaseItems'a {
fn next(mut self) - Option'a ~Base{
match self.iter.next() {
Some(ref baseimpl) = {
Some('a match ***baseimpl{
FirstThinkImpl(ref first) = *first as ~Base,
SecondThinkImpl(ref second)= *second as ~Base,
})
},
None = None,
}
}
}

But I have a lifetime problem. The error is : borrowed value does not 
live long enough and reference must be valid for the lifetime 'a  as 
defined on the block

and :
cannot move out of dereference of ``-pointer SecondThinkImpl(ref 
second)= *second as ~Base,


Another possibility:
fn next(mut self) - Option'a ~Base{
match self.iter.next() {
Some(ref baseimpl) = {
Some(match ***baseimpl{
FirstThinkImpl(ref first) = first as 'a ~Base,
SecondThinkImpl(ref second)= second as 'a ~Base,
})
},
None = None,
}
}
generate the error: non-scalar cast: `~FirstThink` as `'a 
~Baseno-bounds`


I try different possibility but I didn't find how to return a 'a 
lifetime ~Base or Base


I remove the mut to simplify the test of the different lifetime 
possibilities.


Philippe

Le 07/04/2014 10:27, Rodrigo Rivas a écrit :

On Sun, Apr 6, 2014 at 7:50 PM, Philippe Delrieu
philippe.delr...@free.fr wrote:

I need some more help.

The impl Iteratormut  ~Base for Container declaration generate the error:
error: missing lifetime specifier
So I had it but I can't manage to return the next value with the specified
life time.
The code :
impl'a Iterator'a mut  ~Base for Container {
 /// Advance the iterator and return the next value. Return `None` when
the end is reached.
 fn next(mut self) - Option'a mut ~Base{
 if self.iter_counter == self.nodeList.len()   {
 None
 } else  {
 self.iter_counter += 1;
 Some('a mut match **self.nodeList.get(self.iter_counter){
 FirstThinkImpl(first) = first as ~Base,
 SecondThinkImpl(second)= second as ~Base,
 })
 }
 }
}

Generate these errors :
test_enum.rs:58:18: 61:14 error: borrowed value does not live long enough
test/test_enum.rs:58 Some('a mut match

Oh, I think I may have misleaded you... You cannot implement the
iterator directly in Container, because the iterator must handle the
current position, while the Container just holds the values. You need
a intermediate struct that implements the Iterator traits. That's what
the `iter()` and ' move_iter()` functions do for vectors and other
standard containers. So you'll need something along the lines of this
(disclaimer: totally untested!!):

struct Container {
 //
 fn iter('a self) - BaseItems'a {
let iter = nodeList.iter();
BaseItems{ iter : iter }
 }
}

struct BaseItems'a {
 iter : Items'a, ~Base
}

impl'a Iterator'a mut  ~Base for BaseItems'a {
 //
}

BTW, why all the double pointer in all the mut ~Base instead of
just mut Base?



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


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

2014-04-06 Thread Philippe Delrieu

I need some more help.

The impl Iteratormut  ~Base for Container declaration generate the 
error:  error: missing lifetime specifier
So I had it but I can't manage to return the next value with the 
specified life time.

The code :
impl'a Iterator'a mut  ~Base for Container {
/// Advance the iterator and return the next value. Return `None` 
when the end is reached.

fn next(mut self) - Option'a mut ~Base{
if self.iter_counter == self.nodeList.len()   {
None
} else  {
self.iter_counter += 1;
Some('a mut match **self.nodeList.get(self.iter_counter){
FirstThinkImpl(first) = first as ~Base,
SecondThinkImpl(second)= second as ~Base,
})
}
}
}

Generate these errors :
test_enum.rs:58:18: 61:14 error: borrowed value does not live long enough
test/test_enum.rs:58 Some('a mut match 
**self.nodeList.get(self.iter_counter){
test/test_enum.rs:59 FirstThinkImpl(first) = first as 
~Base,

test_enum.rs:60 SecondThinkImpl(second)= second as ~Base,
test_enum.rs:61 })
test_enum.rs:53:52: 63:6 note: reference must be valid for the lifetime 
'a  as defined on the block at 53:51...

test_enum.rs:53 fn next(mut self) - Option'a mut ~Base{
test_enum.rs:54 if self.iter_counter == self.nodeList.len()   {
test/test_enum.rs:55 None
test_enum.rs:56 } else  {
test_enum.rs:57 self.iter_counter += 1;
test_enum.rs:58 Some('a mut match 
**self.nodeList.get(self.iter_counter){

...
test_enum.rs:56:17: 62:10 note: ...but borrowed value is only valid for 
the expression at 56:16

test_enum.rs:56 } else  {
test_enum.rs:57 self.iter_counter += 1;
test_enum.rs:58 Some('a mut match 
**self.nodeList.get(self.iter_counter){

test_enum.rs:59 FirstThinkImpl(first) = first as ~Base,
test_enum.rs:60 SecondThinkImpl(second)= second as ~Base,
test/test_enum.rs:61 })
...
test_enum.rs:59:17: 59:38 error: cannot move out of dereference of 
``-pointer

test_enum.rs:59 FirstThinkImpl(first) = first as ~Base,
^
test_enum.rs:60:17: 60:40 error: cannot move out of dereference of 
``-pointer

test_enum.rs:60 SecondThinkImpl(second)= second as ~Base,



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 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;

impl Base for FirstThink{
   fn set_something(mut self){}
}

struct SecondThink;
impl Base for SecondThink{
   fn set_something(mut self){}
}

enum BaseImpl{
 FirstThinkImpl(~FirstThink),
 SecondThinkImpl(~SecondThink),
}

fn some_process(list: mut Vecmut ~Base){
 for think in list.mut_iter()   {
 think.set_something();
 }
}

struct Container{
 nodeList: Vec~BaseImpl,
}

impl Container{
 fn add_FirstThink(mut self, think: ~FirstThink){
 self.nodeList.push(~FirstThinkImpl(think));
 }
 fn add_SecondThink(mut self, think: ~SecondThink){
 self.nodeList.push(~SecondThinkImpl(think));
 }

 fn do_some_process(mut self, fct: fn(mut Vecmut ~Base)){
  I didn't find a simple  way to convert the Vec~BaseImpl to a mut
Vecmut ~Base
  to do the call
fct(self.nodeList);

 }
}

I use the enum pattern to have only one collection of object that impl Base
but sometime I have to do specific processing depending if the Base is a
FirstThink or SecondThink (not in the example). I use the match as follow

match think {
 FirstThinkImpl(first) = do specific first,
 SecondThinkImpl(second)= do specific second,
});

Perhaps there is a better way to do. Any suggestions would  be appreciated.

I think that would be better if the `fct` function take an
`std::iter::Iteratormut ~Base` instead of a `Vec`. Naturally, you
will not be able to modify the vector, only to iterate through it. But
if `fct` is allowed to modify the vector your requirements are
impossible in the first place!

Then you can write a simple adaptor:

impl std::iter::Iteratormut ~Base for Container {
 // left as an exercise to the reader ;-)
}



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


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 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;

impl Base for FirstThink{
   fn set_something(mut self){}
}

struct SecondThink;
impl Base for SecondThink{
   fn set_something(mut self){}
}

enum BaseImpl{
 FirstThinkImpl(~FirstThink),
 SecondThinkImpl(~SecondThink),
}

fn some_process(list: mut Vecmut ~Base){
 for think in list.mut_iter()   {
 think.set_something();
 }
}

struct Container{
 nodeList: Vec~BaseImpl,
}

impl Container{
 fn add_FirstThink(mut self, think: ~FirstThink){
 self.nodeList.push(~FirstThinkImpl(think));
 }
 fn add_SecondThink(mut self, think: ~SecondThink){
 self.nodeList.push(~SecondThinkImpl(think));
 }

 fn do_some_process(mut self, fct: fn(mut Vecmut ~Base)){
  I didn't find a simple  way to convert the Vec~BaseImpl to a mut
Vecmut ~Base
  to do the call
fct(self.nodeList);

 }
}

I use the enum pattern to have only one collection of object that impl Base
but sometime I have to do specific processing depending if the Base is a
FirstThink or SecondThink (not in the example). I use the match as follow

match think {
 FirstThinkImpl(first) = do specific first,
 SecondThinkImpl(second)= do specific second,
});

Perhaps there is a better way to do. Any suggestions would  be appreciated.

I think that would be better if the `fct` function take an
`std::iter::Iteratormut ~Base` instead of a `Vec`. Naturally, you
will not be able to modify the vector, only to iterate through it. But
if `fct` is allowed to modify the vector your requirements are
impossible in the first place!

Then you can write a simple adaptor:

impl std::iter::Iteratormut ~Base for Container {
 // left as an exercise to the reader ;-)
}



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


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

2014-04-04 Thread Philippe Delrieu

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;

impl Base for FirstThink{
  fn set_something(mut self){}
}

struct SecondThink;
impl Base for SecondThink{
  fn set_something(mut self){}
}

enum BaseImpl{
FirstThinkImpl(~FirstThink),
SecondThinkImpl(~SecondThink),
}

fn some_process(list: mut Vecmut ~Base){
for think in list.mut_iter()   {
think.set_something();
}
}

struct Container{
nodeList: Vec~BaseImpl,
}

impl Container{
fn add_FirstThink(mut self, think: ~FirstThink){
self.nodeList.push(~FirstThinkImpl(think));
}
fn add_SecondThink(mut self, think: ~SecondThink){
self.nodeList.push(~SecondThinkImpl(think));
}

fn do_some_process(mut self, fct: fn(mut Vecmut ~Base)){
 I didn't find a simple  way to convert the Vec~BaseImpl to a 
mut Vecmut ~Base

 to do the call
   fct(self.nodeList);

}
}

I use the enum pattern to have only one collection of object that impl 
Base but sometime I have to do specific processing depending if the Base 
is a FirstThink or SecondThink (not in the example). I use the match as 
follow


match think {
FirstThinkImpl(first) = do specific first,
SecondThinkImpl(second)= do specific second,
});

Perhaps there is a better way to do. Any suggestions would  be appreciated.

Philippe


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


Re: [rust-dev] Using a closure as a return value

2014-02-22 Thread Philippe Delrieu
Thank for you reply. But I don't see any solution to my problem.. I'll 
explain it a little more.


I want to develop a sort of GUI. The GUI has its own logic and use a 
rendering engine to do the work. I want my GUI separate of the rendering 
engine.
In the first solution I use a trait that hide the renderer. So I have a 
struct that old the renderer that implement the trait. It is created at 
the start of ther application and  passed to every GUI call. At the end 
the trait is casted to the effective renderer to do the work:


trait Renderer{}
struct MyRender{
API_render: ~effectiveRenderer,
}

impl Renderer for MyRender{}

struct MyGUIWidget;

impl MyGUIWidget {
fn draw(self, renderer: renderer){  //here I know what type 
of renderer to use.
let myrender  = render as MyRender; //error: non-scalar cast: 
`Rendererno-bounds` as `MyRender`

myrender.API_render.render();
}
}

#[main]
fn main() {
let render = MyRender{API_render: ~...}; //init with user choice 
renderer

let widget = MyGUIWidget;
widget.draw(render); //draw
}

I didn't find a way to send specific Renderer to an API with a generic 
trait and to polymorph it when I know which struct it is.


I can use a singleton or a static variable but static allocation doesn't 
seem to be allowed (as I undersdant the documentation).


So I try with closure and I have a sort of example working using a 
renderer :

trait Renderer{} //

struct MyRender{
API_render: ~effectiveRenderer,
}

impl Renderer for MyRender{}


trait Container{
fn draw(self, draw_render: ||);
}

struct MyContainer{
value :~str,
}

impl Container for MyContainer {
fn draw(self, draw_render: ||){
draw_render();
}
}

#[main]
fn main() {
 let render = MyRender{API_render: ~StringRender}; //init with user 
choice renderer

let container = MyContainer{value: ~value};
container.draw(||{
render.API_render.render(container.value);
}); //draw
}

To extend my API I need to use more closure and if I don't what to 
construct every thing in the main I have to return closure constructed 
by each widget for example.


My last idea is to use a spawned task that hold the renderer and send it 
the widget to draw but It seems to me a little complicated.


So I don't see any simple to do it. If anybody can help, it would be 
very helpful.


Philippe

Le 20/02/2014 04:14, Jack Moffitt a écrit :

I'am learning the functional programming paradigm with rust and to help me I
decide to translate the pattern of the book Functional Programming Patterns
in Scala and Clojure in Rust. In this work I have a problem to return a
closure (or a function) as a return value and I didn't find any solution. I
understand the problem but I can't find a solution. The code is :

Closures in Rust are stack allocated, so you can't return them from a
function since the function's stack will be gone. You can use either a
proc() or a ~Trait object. A proc can only be called once, but a trait
object can be called many times. If you don't need to close over any
state (which it appears you don't from your example), then you can
return bare functions.

Here's a trait object example (untested and incomplete):

trait Comparison {
   fn compare(self, p1: Person, p2: Person) - Ordering;
}

fn make_comparison() - ~Comparison {
   struct ClosedOverState {
  ...
   }
   impl Comparison for ClosedOverState {
 fn compare(...) - Ordering {
 // access state through self.foo
 }
   }

   ~ClosedOverState {
 foo: 0,
   }
}

It can be simplified with macros.

jack.




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


Re: [rust-dev] How to use dynamic polymorphism with collection

2014-02-09 Thread Philippe Delrieu

Thank you.
My problem is more complex than the example I gave. Your answer help me 
in reorganizing my code. I use a lib that as generic method that why I 
put generic in the example. I remove them and change the way I pass 
parameters. I didn't solve everything but I think I'm progressing.

If I don't find the answer I'll post a new example.

Philippe

Le 09/02/2014 00:56, Ashish Myles a écrit :
On Sat, Feb 8, 2014 at 6:48 PM, Ashish Myles marci...@gmail.com 
mailto:marci...@gmail.com wrote:



On Sat, Feb 8, 2014 at 1:21 PM, Philippe Delrieu
philippe.delr...@free.fr mailto:philippe.delr...@free.fr wrote:

pub trait Base {
fn do_base(self);
}

struct TestBase;

impl Base for TestBase{
fn do_base(self){
println!(ici);
}
}

trait GenerciFn{
fn do_genericT: Base(self, base: T);
}

struct DoGenericFn;

impl GenerciFn for DoGenericFn {
fn do_genericT: Base(self, base: T){
base.do_base();
}
}

struct ToTestStr{
vec_gen: ~[~TestBase],
}

impl ToTestStr{
fn testgencallT: GenerciFn(self, gen: T){
for base in self.vec_gen.iter(){
//let test = base as ~TestBase;
gen.do_generic(**base);
}
}
}

#[main]
fn main() {
let base = TestBase;
let test = ToTestStr {vec_gen: ~[~base],};
let gen = DoGenericFn;
test.testgencall(gen);



It took me a few attempts to get the for loop right, but here you go.


pub trait Base {
fn do_base(self);
}

struct TestBase;

impl Base for TestBase {
fn do_base(self) {
println!(ici);
}
}

trait GenericFn {
fn do_generic(self, base: Base);
}

struct DoGenericFn;

impl GenericFn for DoGenericFn {
fn do_generic(self, base: Base) {
base.do_base();
}
}

struct ToTestStr {
vec_gen: ~[~Base],
}

impl ToTestStr {
fn testgencallT: GenericFn(self, gen: T){
for ref base in self.vec_gen.iter() {
gen.do_generic(**base);
}
}
}

#[main]
fn main() {
let testbase = TestBase;
let test = ToTestStr {vec_gen: ~[~testbase as ~Base],};

let gen = DoGenericFn;
test.testgencall(gen);
}


Also, for a little more runtime polymorphism, you could change 
testgencall's declaration to

fn testgencall(self, gen: GenericFn) {
...
}


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


Re: [rust-dev] rustpkg error: Package ____ depends on ____, but I don't know how to find it

2014-01-28 Thread Philippe Delrieu

Any info or idea?
I update from the master and now all my project have the same issue.
If I use rustc I have no problem. I see the thread about rustpkg, 
perhaps I should migrate to rustc and cmake?


Philippe

Le 26/01/2014 16:25, Philippe Delrieu a écrit :

Hi,

I have the same problem since 2 or 3 days with the portmidi project.

Philippe

Le 26/01/2014 14:06, Cadence Marseille a écrit :

Hi,

I am seeing a new build error and I am not sure what is causing it. 
rust-pcre https://github.com/cadencemarseille/rust-pcre, libpcre 
bindings for Rust, is set up to use Travis and Rust CI 
http://rust-ci.org/.  The latest build is failing with:


rustpkg install pcre

WARNING: The Rust package manager is experimental and may be unstable

error: Package pcre depends on extra, but I don't know how to find it

task 'unnamed' failed at 'explicit failure', 
/build/buildd/rust-nightly-201401260405~897a0a3~precise/src/librustpkg/util.rs:531 
http://util.rs:531


task 'main' failed at 'receiving on a closed channel', 
/build/buildd/rust-nightly-201401260405~897a0a3~precise/src/libstd/comm/mod.rs:743 
http://mod.rs:743


task 'unnamed' failed at 'Error running custom build command', 
/build/buildd/rust-nightly-201401260405~897a0a3~precise/src/librustpkg/lib.rs:517 
http://lib.rs:517


make: *** [install] Error 65


See https://travis-ci.org/cadencemarseille/rust-pcre/builds/17643218

I looked at some other Rust CI-enabled projects and found a similar 
error:

https://travis-ci.org/eholk/rust-opencl/builds/17491630
https://travis-ci.org/erickt/rust-zmq/builds/16353359
https://travis-ci.org/erickt/rust-mustache/builds/16059551
https://travis-ci.org/bjz/gl-rs/builds/16126945
https://travis-ci.org/bjz/sax-rs/builds/16405581

What is causing this error and how do I fix it?

Cadence


___
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


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


Re: [rust-dev] Bitwise operations in rust.

2014-01-15 Thread Philippe Delrieu
Thanks for you answer . I have the idea to see in the SDL port (I work 
on the SDL2 port) which is finished and has the same problems. They 
solve the problem like this :


pub fn unfold_bits(bitflags: u32) - ~[SDL_WindowFlags] {
let flags = [SDL_WINDOW_FULLSCREEN,
SDL_WINDOW_OPENGL,
SDL_WINDOW_SHOWN,
SDL_WINDOW_HIDDEN,
SDL_WINDOW_BORDERLESS,
SDL_WINDOW_RESIZABLE,
SDL_WINDOW_MINIMIZED,
SDL_WINDOW_MAXIMIZED,
SDL_WINDOW_INPUT_GRABBED,
SDL_WINDOW_INPUT_FOCUS,
SDL_WINDOW_MOUSE_FOCUS,
SDL_WINDOW_FULLSCREEN_DESKTOP,
SDL_WINDOW_FOREIGN
];

   flags.iter().filter_map(|flag| {
if bitflags  (flag as u32) != 0 { Some(flag) }
else { None }
}).collect()
}

Philippe

Le 15/01/2014 17:36, SiegeLord a écrit :

On 01/15/2014 11:29 AM, Nicolas Silva wrote:

I think enums are not a good fit for bitwise operations, it's not really
meant for that.
I came to the same conclusion and came up with a nice macro to 
automate that, seen here: 
https://github.com/SiegeLord/RustAllegro/blob/master/src/rust_util.rs#L3..L56 
and used here 
https://github.com/SiegeLord/RustAllegro/blob/master/src/allegro/internal/bitmap_like.rs#L9..L23 
.


This enables a nice, C-like API when composing/extracting flags via 
the bit-or and bit-and operators.


-SL
___
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


Re: [rust-dev] error: can't find crate for `std`

2014-01-03 Thread Philippe Delrieu
I found the problem. I had to rebuild all my external C binding that was 
compiled with the old version of rustc.

Before rustc were crashing. Now I have this error.

Philippe


Le 02/01/2014 22:40, Philippe Delrieu a écrit :
I update with the master and now I have this error with a code that 
was compiling before.

... rs:1:1: 1:1 error: can't find crate for `std`

The error is at the first line which ever was the first line. Not all 
crate have the problem.


Philippe Delrieu


___
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


[rust-dev] error: can't find crate for `std`

2014-01-02 Thread Philippe Delrieu
I update with the master and now I have this error with a code that was 
compiling before.

... rs:1:1: 1:1 error: can't find crate for `std`

The error is at the first line which ever was the first line. Not all 
crate have the problem.


Philippe Delrieu


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


Re: [rust-dev] How to send a closure in a task

2013-12-25 Thread Philippe Delrieu

Thank you for your help.

I test extern Rust fn(u64, T) and it works when I use a declared 
function. I didn't manage to make it works with a closure.


For the 'static |u64, T| I have the same error :

cannot capture variable of type `'static |u64, T|`, which does not 
fulfill `Send`, in a bounded closure


The function signature :
pub fn Pt_startT:Send (self, resolution : u64, userData : T , 
callback: 'static |u64, T|) {


Philippe

Le 24/12/2013 19:06, Patrick Walton a écrit :

On 12/24/13 3:41 AM, Philippe Delrieu wrote:

Hello,

I try to capture a closure in a task and I have the error:
error: cannot capture variable of type `|u64, T|`, which does not
fulfill `Send`, in a bounded closure

Any hint to make the closure 'send-able'?


Try `'static |u64, T|` or `extern Rust fn(u64, T)`.

Patrick

___
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


[rust-dev] How to send a closure in a task

2013-12-24 Thread Philippe Delrieu

Hello,

I try to capture a closure in a task and I have the error:
error: cannot capture variable of type `|u64, T|`, which does not 
fulfill `Send`, in a bounded closure


Any hint to make the closure 'send-able'?

The code I use :

pub fn Pt_startT:Send (resolution : u64, userData : T , callback: 
|u64 , T|) {

let mut task = task::task();
task.sched_mode(task::SingleThreaded);
do task.spawn || {
let mut timer = timer::Timer::new().unwrap();
let periodic = timer.periodic(resolution);
loop {
periodic.recv();
callback(10, userData);
}

}

}

thank for your help.

Philippe Delrieu

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


[rust-dev] new compile errors in the master since a few days

2013-12-05 Thread Philippe Delrieu

Hello,

since a few days, I have a lot of new errors in the master compiler. For 
example in the rust_zmq lib that I use. When I compile it I have these 
errors :
321:9 error: last argument in `do` call has non-procedure type: |*i8| - 
V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:319 
let rc = do endpoint.with_c_str |cstr| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:320 
unsafe {zmq_bind(self.sock, cstr)}
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:321 
};
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328:29: 
330:9 error: last argument in `do` call has non-procedure type: |*i8| - 
V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328 
let rc = do endpoint.with_c_str |cstr| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:329 
unsafe {zmq_connect(self.sock, cstr)}
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:330 
};
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337:16: 
352:9 error: last argument in `do` call has non-procedure type: |*u8, 
uint| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337 
do data.as_imm_buf |base_ptr, len| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:338 
let msg = [0, ..32];

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:339
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:340 
unsafe {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:341 
// Copy the data into the message.
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342 
zmq_msg_init_size(msg, len as size_t);

...
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342:40: 
342:43 error: the type of this value must be known in this context
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342 
zmq_msg_init_size(msg, len as size_t);

^~~
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344:16: 
344:32 error: cannot determine a type for this bounded type parameter: 
unconstrained type
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344 
ptr::copy_memory(::cast::transmute(zmq_msg_data(msg)), base_ptr, len);

^~~~
I have the same type of errors in my code plus other error when the 
trait can't be found like type `MyType` does not implement any method in 
scope named `encode` and the function is implemented just above.

This code where compiling last week.

Philippe Delrieu

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


Re: [rust-dev] new compile errors in the master since a few days

2013-12-05 Thread Philippe Delrieu

Thank you it correct my first problems.

I didn't send code because I thought it has the same cause. For the last 
problems the code is :


use extra::serialize;
use extra::json::{Json, Decoder, ToJson, Object, Encoder, Decoder};
use extra::treemap::TreeMap;
use std::io::Decorator;

//second struct with manually implemented  Decodable, Encodable
#[deriving(Decodable, Encodable, Eq)]
pub struct TestStruct2{
dataInt: u8,
dataStr:~str,
dataArray:~[u8],
}

let test3 : TestStruct2 = TestStruct2 {dataInt: 1, dataStr:~toto, 
dataArray:~[2,3,4,5]}; 
//{\dataArray\:[2,3,4,5],\dataInt\:1,\dataStr\:\toto\}

let mut m3 = MemWriter::new();
{
let mut encoder3 =Encoder::init(mut m3 as mut Writer);
test3.encode(mut encoder3);
}

Rustc result :
test_json.rs:292:8: 292:36 error: type `TestStruct2` does not implement 
any method in scope named `encode`

test/test_json.rs:292 test3.encode(mut encoder3);

Philippe



Le 05/12/2013 09:56, Kevin Ballard a écrit :

`do` no longer works with stack closures. It now only works with the new proc() 
type, which basically means you're only going to see it used with spawn().

You need to now say something like

 let rc = endpoint.with_c_str(|cstr| {
 unsafe {smq_bind(self.sock, cstr)}
 });

I can't speculate on your encode error without seeing it.

-Kevin

On Dec 5, 2013, at 12:43 AM, Philippe Delrieu philippe.delr...@free.fr wrote:


Hello,

since a few days, I have a lot of new errors in the master compiler. For 
example in the rust_zmq lib that I use. When I compile it I have these errors :
321:9 error: last argument in `do` call has non-procedure type: |*i8| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:319 let 
rc = do endpoint.with_c_str |cstr| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:320 
unsafe {zmq_bind(self.sock, cstr)}
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:321 };
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328:29: 330:9 
error: last argument in `do` call has non-procedure type: |*i8| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328 let 
rc = do endpoint.with_c_str |cstr| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:329 
unsafe {zmq_connect(self.sock, cstr)}
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:330 };
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337:16: 352:9 
error: last argument in `do` call has non-procedure type: |*u8, uint| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337 do 
data.as_imm_buf |base_ptr, len| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:338 let 
msg = [0, ..32];
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:339
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:340 
unsafe {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:341 // 
Copy the data into the message.
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342 
zmq_msg_init_size(msg, len as size_t);
...
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342:40: 
342:43 error: the type of this value must be known in this context
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342 
zmq_msg_init_size(msg, len as size_t);
^~~
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344:16: 
344:32 error: cannot determine a type for this bounded type parameter: 
unconstrained type
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344 
ptr::copy_memory(::cast::transmute(zmq_msg_data(msg)), base_ptr, len);
^~~~
I have the same type of errors in my code plus other error when the trait can't 
be found like type `MyType` does not implement any method in scope named 
`encode` and the function is implemented just above.
This code where compiling last week.

Philippe Delrieu

___
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


Re: [rust-dev] new compile errors in the master since a few days

2013-12-05 Thread Philippe Delrieu

I found my error. It's a classical problem.
TestStruct2 implement the trait `extra::serialize::Encodable` using the 
generated impl by the compiler.

I didn't declare : use extra::serialize::Encodable;
So the compiler doesn't find it and declare the problem at the 
implementation.
It's the same problem when you work with different file and the trait is 
implemented in one file and use in another.
Usually I found the error but I was confused with other errors and the 
message wasn't clear.
Is it possible to change the message by for example in this case trait 
`extra::serialize::Encodable` not found for encode,

or to add all `use` needed when using a type and its implementation.

Philippe

Le 05/12/2013 10:53, Philippe Delrieu a écrit :

Thank you it correct my first problems.

I didn't send code because I thought it has the same cause. For the 
last problems the code is :


use extra::serialize;
use extra::json::{Json, Decoder, ToJson, Object, Encoder, Decoder};
use extra::treemap::TreeMap;
use std::io::Decorator;

//second struct with manually implemented  Decodable, Encodable
#[deriving(Decodable, Encodable, Eq)]
pub struct TestStruct2{
dataInt: u8,
dataStr:~str,
dataArray:~[u8],
}

let test3 : TestStruct2 = TestStruct2 {dataInt: 1, 
dataStr:~toto, dataArray:~[2,3,4,5]}; 
//{\dataArray\:[2,3,4,5],\dataInt\:1,\dataStr\:\toto\}

let mut m3 = MemWriter::new();
{
let mut encoder3 =Encoder::init(mut m3 as mut Writer);
test3.encode(mut encoder3);
}

Rustc result :
test_json.rs:292:8: 292:36 error: type `TestStruct2` does not 
implement any method in scope named `encode`

test/test_json.rs:292 test3.encode(mut encoder3);

Philippe



Le 05/12/2013 09:56, Kevin Ballard a écrit :
`do` no longer works with stack closures. It now only works with the 
new proc() type, which basically means you're only going to see it 
used with spawn().


You need to now say something like

 let rc = endpoint.with_c_str(|cstr| {
 unsafe {smq_bind(self.sock, cstr)}
 });

I can't speculate on your encode error without seeing it.

-Kevin

On Dec 5, 2013, at 12:43 AM, Philippe Delrieu 
philippe.delr...@free.fr wrote:



Hello,

since a few days, I have a lot of new errors in the master compiler. 
For example in the rust_zmq lib that I use. When I compile it I have 
these errors :
321:9 error: last argument in `do` call has non-procedure type: 
|*i8| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:319 
let rc = do endpoint.with_c_str |cstr| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:320 
unsafe {zmq_bind(self.sock, cstr)}
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:321 
};
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328:29: 
330:9 error: last argument in `do` call has non-procedure type: 
|*i8| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328 
let rc = do endpoint.with_c_str |cstr| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:329 
unsafe {zmq_connect(self.sock, cstr)}
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:330 
};
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337:16: 
352:9 error: last argument in `do` call has non-procedure type: 
|*u8, uint| - V3
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337 
do data.as_imm_buf |base_ptr, len| {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:338 
let msg = [0, ..32];
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:339 

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:340 
unsafe {
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:341 
// Copy the data into the message.
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342 
zmq_msg_init_size(msg, len as size_t);

...
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342:40: 
342:43 error: the type of this value must be known in this context
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342 
zmq_msg_init_size(msg, len as size_t);

^~~
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344:16: 
344:32 error: cannot determine a type for this bounded type 
parameter: unconstrained type
/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344 
ptr::copy_memory(::cast::transmute(zmq_msg_data(msg)), base_ptr, len);

^~~~
I have the same type of errors in my code plus other error when the 
trait can't be found like type `MyType` does not implement any 
method in scope named `encode` and the function is implemented just 
above.

This code where compiling last week.

Philippe Delrieu

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

Re: [rust-dev] new compile errors in the master since a few days

2013-12-05 Thread Philippe Delrieu
Perhaps the error message can be more explicit like trait not found for 
method instead of method not found.



Le 05/12/2013 21:57, Corey Richardson a écrit :

No, since it isn't known which trait the method should come from. It
could list *all* the traits that provide that method with that
signature, but even that wouldn't be great if you had the signature
off.

On Thu, Dec 5, 2013 at 3:26 PM, Philippe Delrieu
philippe.delr...@free.fr wrote:

I found my error. It's a classical problem.
TestStruct2 implement the trait `extra::serialize::Encodable` using the
generated impl by the compiler.
I didn't declare : use extra::serialize::Encodable;
So the compiler doesn't find it and declare the problem at the
implementation.
It's the same problem when you work with different file and the trait is
implemented in one file and use in another.
Usually I found the error but I was confused with other errors and the
message wasn't clear.
Is it possible to change the message by for example in this case trait
`extra::serialize::Encodable` not found for encode,
or to add all `use` needed when using a type and its implementation.

Philippe

Le 05/12/2013 10:53, Philippe Delrieu a écrit :


Thank you it correct my first problems.

I didn't send code because I thought it has the same cause. For the last
problems the code is :

use extra::serialize;
use extra::json::{Json, Decoder, ToJson, Object, Encoder, Decoder};
use extra::treemap::TreeMap;
use std::io::Decorator;

//second struct with manually implemented  Decodable, Encodable
#[deriving(Decodable, Encodable, Eq)]
pub struct TestStruct2{
 dataInt: u8,
 dataStr:~str,
 dataArray:~[u8],
}

 let test3 : TestStruct2 = TestStruct2 {dataInt: 1, dataStr:~toto,
dataArray:~[2,3,4,5]};
//{\dataArray\:[2,3,4,5],\dataInt\:1,\dataStr\:\toto\}
 let mut m3 = MemWriter::new();
 {
 let mut encoder3 =Encoder::init(mut m3 as mut Writer);
 test3.encode(mut encoder3);
 }

Rustc result :
test_json.rs:292:8: 292:36 error: type `TestStruct2` does not implement
any method in scope named `encode`
test/test_json.rs:292 test3.encode(mut encoder3);

Philippe



Le 05/12/2013 09:56, Kevin Ballard a écrit :

`do` no longer works with stack closures. It now only works with the new
proc() type, which basically means you're only going to see it used with
spawn().

You need to now say something like

  let rc = endpoint.with_c_str(|cstr| {
  unsafe {smq_bind(self.sock, cstr)}
  });

I can't speculate on your encode error without seeing it.

-Kevin

On Dec 5, 2013, at 12:43 AM, Philippe Delrieu philippe.delr...@free.fr
wrote:


Hello,

since a few days, I have a lot of new errors in the master compiler. For
example in the rust_zmq lib that I use. When I compile it I have these
errors :
321:9 error: last argument in `do` call has non-procedure type: |*i8| -
V3

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:319
let rc = do endpoint.with_c_str |cstr| {

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:320
unsafe {zmq_bind(self.sock, cstr)}

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:321
};

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328:29:
330:9 error: last argument in `do` call has non-procedure type: |*i8| -
V3

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:328
let rc = do endpoint.with_c_str |cstr| {

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:329
unsafe {zmq_connect(self.sock, cstr)}

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:330
};

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337:16:
352:9 error: last argument in `do` call has non-procedure type: |*u8, uint|
- V3

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:337
do data.as_imm_buf |base_ptr, len| {

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:338
let msg = [0, ..32];

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:339

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:340
unsafe {

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:341
// Copy the data into the message.

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342
zmq_msg_init_size(msg, len as size_t);
...

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342:40:
342:43 error: the type of this value must be known in this context

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:342
zmq_msg_init_size(msg, len as size_t);
^~~

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344:16:
344:32 error: cannot determine a type for this bounded type parameter:
unconstrained type

/home/pdelrieu/Documents/dev/musit/rust/zmq/git/rust-zmq/src/zmq/lib.rs:344
ptr::copy_memory(::cast::transmute(zmq_msg_data(msg

Re: [rust-dev] new compile errors in the master since a few days

2013-12-05 Thread Philippe Delrieu

I find this message better than the current. It won't mislead me.

Le 05/12/2013 22:50, Corey Richardson a écrit :

How about method `foo` no found and no trait in scope provided one ?

On Thu, Dec 5, 2013 at 4:29 PM, Philippe Delrieu
philippe.delr...@free.fr wrote:

Perhaps the error message can be more explicit like trait not found for
method instead of method not found.


Le 05/12/2013 21:57, Corey Richardson a écrit :


No, since it isn't known which trait the method should come from. It
could list *all* the traits that provide that method with that
signature, but even that wouldn't be great if you had the signature
off.

On Thu, Dec 5, 2013 at 3:26 PM, Philippe Delrieu
philippe.delr...@free.fr wrote:

I found my error. It's a classical problem.
TestStruct2 implement the trait `extra::serialize::Encodable` using the
generated impl by the compiler.
I didn't declare : use extra::serialize::Encodable;
So the compiler doesn't find it and declare the problem at the
implementation.
It's the same problem when you work with different file and the trait is
implemented in one file and use in another.
Usually I found the error but I was confused with other errors and the
message wasn't clear.
Is it possible to change the message by for example in this case trait
`extra::serialize::Encodable` not found for encode,
or to add all `use` needed when using a type and its implementation.

Philippe




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


Re: [rust-dev] Problem to use Encodable as fn parameter

2013-12-04 Thread Philippe Delrieu

I reply to my questions. It can be helpful to somebody.
First the error: wrong number of lifetime parameters
The struct encoder is declared pub struct Encoder'self so the 'self 
lifetime is part of the type and must be keep.
The good declaration is pub fn 
buffer_encodeT:EncodableEncoder'self(to_encode_object: T) - ~[u8]


The call to the function is : Encoder::buffer_encode(to_encode_object)

For the other questions.
The lifetime has been added to init (pub fn init'a(wr: 'a mut 
io::Writer) - Encoder'a) because the borrowed specified parameter 
(wr) is returning in the Encoder and must be keep borrower after the 
call and during all the Encoder use. Fn Init borrow the wr and give it 
to the Encoder. After the 'init' call, returned Encoder is use to encode 
object and wr must still be borrowed. The call to init and encode are 
put inside a scoped block to manage the Encoder lifetime:

ex:
let mut m = MemWriter::new();
{
let mut encoder = Encoder::init(mut m as mut Writer);
to_encode_object.encode(mut encoder);
}
m.inner()

Why the type is declared with a 'self lifetime (pub struct 
Encoder'self). It's not so clear. What I think, It's because the 
struct contains an attribute (priv wr: 'self mut io::Writer) that have 
a variable lifetime (depend on the use) , so to be configurable the 
lifetime must be declared as a generic in the struct. The variable 
lifetime is needed because, it allow the Encoder to borrow the writer 
during a lifetime longer that the function call (lifetime of normal 
borrowing) needed in the init function.


For more informations:
http://static.rust-lang.org/doc/master/tutorial-borrowed-ptr.html : to 
understand borrowing mechanism
https://www.mail-archive.com/rust-dev@mozilla.org/msg05811.html : for 
the 'self


Hope my explication is clear.

I have remark about the list and the thread 'Rust Forum', I think it 
become important to have a user mailing list or forum. It's the second 
time I answer to my trivial questions and I fell that I'm annoying 
everybody with these.


Philippe Delrieu


Le 01/12/2013 18:28, Philippe Delrieu a écrit :
I see the PR has been approved to I try to implements the method 'pub 
fn buffer_encodeT:EncodableEncoder(to_encode_object: T) - ~[u8]'
and I have this error : error: wrong number of lifetime parameters: 
expected 1 but found 0 and  indicate the Encoder type.


I have another question. I try to understand the modification on 
json.rs and function declaration has changed from :

impl serialize::Encoder for Encoder
to:
impl'self serialize::Encoder for Encoder'self
or
pub fn init'a(wr: 'a mut io::Writer) - Encoder'a
instead of
pub fn new(wr: mut io::Writer) - Encoder

Could you explain me the difference if you don't mind.

Philippe

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


Re: [rust-dev] Problem to use Encodable as fn parameter

2013-11-29 Thread Philippe Delrieu
I made a remark about that on the GitHub pull request where the idea was 
proposed. I'm agree with you. It's simplier  to return a str or perhaps 
a [u8] if it's use in a stream purpose.

I'm not very fan of creating a MemWriter and return it.

I'll modify to add two functions:
pub fn str_encodeT:EncodableEncoder(to_encode_object: T) - ~str
pub fn buffer_encodeT:EncodableEncoder(to_encode_object: T) - ~[u8]

and remove the other.

Any remaqs?

Philippe


Le 29/11/2013 10:44, Gaetan a écrit :


I would prefere this function returns a str.

Le 29 nov. 2013 09:27, Philippe Delrieu philippe.delr...@free.fr 
mailto:philippe.delr...@free.fr a écrit :


Thank you for the help. I've try this signature and I had an
compile error. I thought it came from the signature but the
problem when from the call.
It works now.

For the return type @mut MemWriter I work on the json doc and some
example of use. I can make the change. I didn't find the issue
about it. Did you create it?

Philippe

Le 28/11/2013 22:27, Erick Tryzelaar a écrit :

Good afternoon Phillippe,

Here's how to do it, assuming you're using rust 0.8 and the json
library:

```
#[feature(managed_boxes)];

extern mod extra;

use std::io::mem::MemWriter;
use extra::serialize::{Encoder, Encodable};
use extra::json;

pub fn memory_encode
T: Encodablejson::Encoder
(to_encode_object: T) - @mut MemWriter {
//Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = json::Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
m
}

fn main() {
}
```

Regarding the trouble returning a `MemWriter` instead of a `@mut
MemWriter`, the easiest thing would be to fix library to use
`mut ...` instead of `@mut ...`. I'll put in a PR to do that.



On Thu, Nov 28, 2013 at 3:55 AM, Philippe Delrieu
philippe.delr...@free.fr mailto:philippe.delr...@free.fr wrote:

I try to develop a function that take a Encodable parameter
but I have the error wrong number of type arguments: expected
1 but found 0

pub fn memory_encode(to_encode_object: serialize::Encodable)
- @mut MemWriter  {
   //Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
m
}

The encodable trait is :
pub trait EncodableS:Encoder {
fn encode(self, s: mut S);
}

I try this definition
memory_encodeT:serialize::EncodableEncoder(to_encode_object:
T) - @mut MemWriter

But I can't use the method with a struct that implement
Encodable. The error : mismatched types: expected `V31`
but found ..

I have another question :
I would like to return a MemWriter and not a @mut MemWriter .
I didn't find a way to convert the @mut to ~

Philippe Delrieu
___
Rust-dev mailing list
Rust-dev@mozilla.org mailto:Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev





___
Rust-dev mailing list
Rust-dev@mozilla.org mailto: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


Re: [rust-dev] Problem to use Encodable as fn parameter

2013-11-29 Thread Philippe Delrieu
I try to implement the two methods and I have a problem with the copy of 
memory.

The first attempt :

 pub fn buffer_encodeT:EncodableEncoder(to_encode_object: T) - 
~[u8]  {

   //Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
let buff:~[u8] = m.inner_ref();
(buff.clone())
}

pub fn str_encodeT:EncodableEncoder(to_encode_object: T) - ~str  {
let buff:~[u8] = buffer_encode(to_encode_object);
str::from_utf8(*buff)
}

When I call str_encode I copy at least two times the content of the 
MemWriter buffer (one inside clone and one inside from_utf8).

If I implements str_encode like that

pub fn str_encodeT:EncodableEncoder(to_encode_object: T) - ~str  {
let m = @mut MemWriter::new();
let mut encoder = Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
let buff:~[u8] = m.inner_ref();
str::from_utf8(*buff)
}

I'll do at least one copy (one less than the other impl) but the code is 
copied.


Is there a better way to manage pointer of memory across function calls?

Philippe

Le 29/11/2013 12:55, Philippe Delrieu a écrit :
I made a remark about that on the GitHub pull request where the idea 
was proposed. I'm agree with you. It's simplier  to return a str or 
perhaps a [u8] if it's use in a stream purpose.

I'm not very fan of creating a MemWriter and return it.

I'll modify to add two functions:
pub fn str_encodeT:EncodableEncoder(to_encode_object: T) - ~str
pub fn buffer_encodeT:EncodableEncoder(to_encode_object: T) - ~[u8]

and remove the other.

Any remaqs?

Philippe


Le 29/11/2013 10:44, Gaetan a écrit :


I would prefere this function returns a str.

Le 29 nov. 2013 09:27, Philippe Delrieu philippe.delr...@free.fr 
mailto:philippe.delr...@free.fr a écrit :


Thank you for the help. I've try this signature and I had an
compile error. I thought it came from the signature but the
problem when from the call.
It works now.

For the return type @mut MemWriter I work on the json doc and
some example of use. I can make the change. I didn't find the
issue about it. Did you create it?

Philippe

Le 28/11/2013 22:27, Erick Tryzelaar a écrit :

Good afternoon Phillippe,

Here's how to do it, assuming you're using rust 0.8 and the json
library:

```
#[feature(managed_boxes)];

extern mod extra;

use std::io::mem::MemWriter;
use extra::serialize::{Encoder, Encodable};
use extra::json;

pub fn memory_encode
T: Encodablejson::Encoder
(to_encode_object: T) - @mut MemWriter {
//Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = json::Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
m
}

fn main() {
}
```

Regarding the trouble returning a `MemWriter` instead of a `@mut
MemWriter`, the easiest thing would be to fix library to use
`mut ...` instead of `@mut ...`. I'll put in a PR to do that.



On Thu, Nov 28, 2013 at 3:55 AM, Philippe Delrieu
philippe.delr...@free.fr mailto:philippe.delr...@free.fr wrote:

I try to develop a function that take a Encodable parameter
but I have the error wrong number of type arguments:
expected 1 but found 0

pub fn memory_encode(to_encode_object:
serialize::Encodable) - @mut MemWriter  {
   //Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
m
}

The encodable trait is :
pub trait EncodableS:Encoder {
fn encode(self, s: mut S);
}

I try this definition
memory_encodeT:serialize::EncodableEncoder(to_encode_object:
T) - @mut MemWriter

But I can't use the method with a struct that implement
Encodable. The error : mismatched types: expected `V31`
but found ..

I have another question :
I would like to return a MemWriter and not a @mut MemWriter
. I didn't find a way to convert the @mut to ~

Philippe Delrieu
___
Rust-dev mailing list
Rust-dev@mozilla.org mailto:Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev





___
Rust-dev mailing list
Rust-dev@mozilla.org mailto: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


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


[rust-dev] Problem to use Encodable as fn parameter

2013-11-28 Thread Philippe Delrieu
I try to develop a function that take a Encodable parameter but I have 
the error wrong number of type arguments: expected 1 but found 0


pub fn memory_encode(to_encode_object: serialize::Encodable) - @mut 
MemWriter  {

   //Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = Encoder(m as @mut Writer);
to_encode_object.encode(mut encoder);
m
}

The encodable trait is :
pub trait EncodableS:Encoder {
fn encode(self, s: mut S);
}

I try this definition
memory_encodeT:serialize::EncodableEncoder(to_encode_object: T) - 
@mut MemWriter


But I can't use the method with a struct that implement Encodable. The 
error : mismatched types: expected `V31` but found ..


I have another question :
I would like to return a MemWriter and not a @mut MemWriter . I didn't 
find a way to convert the @mut to ~


Philippe Delrieu
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Json example code

2013-11-26 Thread Philippe Delrieu

I try to commit my change on json.rs but I didn't manage to make it work.
I'am not very use to git. I've done :
git clone https://github.com/mozilla/rust.git
git rebase master
git push  -- error 403. I use my github account

Sorry for to ask for get but can anybody tell me what to do to send my 
change.


Philippe Delrieu

Le 22/11/2013 19:22, Philippe Delrieu a écrit :
I've done the modification in json.rs (add comment with sample code in 
md format and test code).

I've do the commit and git pull.

The test compile but I didn't manage to run it.
I use the command: make -j 20 check TESTNAME=src/libextra/json.rs
There are errors before and when I force the assert to false I have no 
error for json.


Tell me if it's ok.

Philippe

Le 22/11/2013 10:07, Corey Richardson a écrit :

On Fri, Nov 22, 2013 at 3:33 AM, Philippe Delrieu
philippe.delr...@free.fr wrote:
I finished my test with the rust json API. I made a non trivial 
example code
that summaries what I understand. I put it at the end of the mail. 
Could
someone (the developer of the API for example) add it to the comment 
of the
json API. I don't think I have the right. It can be good to add it 
as a test

case to validate that it stay up to date.
Put any remarks about the code if I've made some mistake or if there is
better code.


Send a pull request adding it.




___
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


Re: [rust-dev] error: cannot move out of dereference of @ pointer

2013-11-22 Thread Philippe Delrieu

I found the answer of my questions:
for ~[u8] convertion in string : std::str::from_utf8();

For  m.inner() error : use m.inner_ref()

Philippe

Le 20/11/2013 14:15, philippe.delr...@free.fr a écrit :

I'am still testing the json lib and I try to encode the json using
extra::json::Encoder. The code I use is :
 let mut encoder = extra::json::Encoder(m as @mut Writer);
 test.encode(mut encoder);
 let st:~[u8] = m.inner();

I have the error : error: cannot move out of dereference of @ pointer

the inner is declared as follow :
 /// Because this takes `self' one could never 'undecorate' a Reader/Writer
 /// that has been boxed. Is that ok? This feature is mostly useful for
 /// extracting the buffer from MemWriter
 fn inner(self) - T;

My second question is how to convert a ~[u8]  to a ~std ?

Philippe Delrieu

___
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


[rust-dev] Json example code

2013-11-22 Thread Philippe Delrieu
I finished my test with the rust json API. I made a non trivial example 
code that summaries what I understand. I put it at the end of the mail. 
Could someone (the developer of the API for example) add it to the 
comment of the json API. I don't think I have the right. It can be good 
to add it as a test case to validate that it stay up to date.
Put any remarks about the code if I've made some mistake or if there is 
better code.


I have a general remark about the json.rs. It's copyrighted by Rust 
developer and google.


Philippe

The code :

#[link(name = test_json, vers = 0.1, author = Philippe Delrieu)];
#[feature(managed_boxes)];

extern mod extra;

use std::io::mem::MemWriter;

use extra::serialize::Decodable;
use extra::serialize::Encodable;
use extra::serialize::Encoder;
use extra::json::{Json, Decoder, ToJson, Object};
use extra::treemap::TreeMap;
use std::io::Decorator;

//first struct with auto generate  Decodable, Encodable
#[deriving(Decodable, Encodable, Eq)] //generate Decodable, Encodable 
impl. Eq is added for the test assert.

pub struct TestStruct1{
dataInt: u8,
dataStr:~str,
dataArray:~[u8],
}

fn Test1(){

//first possibility to use JSON is the serialization API. Use a 
struct that implement Decodable, Encodable.

//the object to test
let test : TestStruct1 = TestStruct1 {dataInt: 1, dataStr:~toto, 
dataArray:~[2,3,4,5]}; // encoded 
~{\dataInt\:1,\dataStr\:\toto\,\dataArray\:[2,3,4,5]}


//Serialize the object in a string using a writer
let m = @mut MemWriter::new();
let mut encoder = extra::json::Encoder(m as @mut Writer);
test.encode(mut encoder);
let buf:~[u8] = m.inner_ref(); //get the serialized values.
let s = std::str::from_utf8(*buf);

println!(test 1 encoded using auto generated Encodable {:?}, s);
assert_eq!(s, 
~{\dataInt\:1,\dataStr\:\toto\,\dataArray\:[2,3,4,5]});


//unserialize using the object decoder
//convert the string to a json object.
let jsonobject = extra::json::from_str(s);
let mut decoder = Decoder(jsonobject.unwrap());
let decoded1: TestStruct1 = Decodable::decode(mut decoder); 
//create the final object
println!(test 1 decoded using auto generated Decodable {:?}, 
decoded1);

assert_eq!(decoded1, test);

}

//second struct with manually implemented  Decodable, Encodable
#[deriving(Eq)] //generate impl of Eq for the test assert.
pub struct TestStruct2{
dataInt: u8,
dataStr:~str,
dataArray:~[u8],
}

implS:Encoder EncodableS for TestStruct2 {
fn encode(self, s: mut S) {
  do s.emit_struct(TestStruct2, 2) |s| {  //2 correspond to 
len the number of field in the structure.

s.emit_struct_field(dataInt, 0, |s| self.dataInt.encode(s));
s.emit_struct_field(dataStr, 1, |s| self.dataStr.encode(s));
//encode the dataArray array field with emit_seq
do s.emit_struct_field(dataArray, 3) |s| {
  do s.emit_seq(self.dataArray.len()) |s| {  //len 
number of element in the array.

  for i in range(0u, self.dataArray.len()){
s.emit_seq_elt(i, |s| self.dataArray[i].encode(s));
  }
}
}
}
   }
}

 implD:extra::serialize::Decoder extra::serialize::DecodableD for 
TestStruct2 {

fn decode(d: mut D) - TestStruct2 {
do d.read_struct(TestStruct2, 1) |d| {
TestStruct2
{
dataInt: d.read_struct_field(dataInt, 0, |d| 
d.read_u8()),
dataStr: d.read_struct_field(dataStr, 1, |d| 
d.read_str()),


dataArray: do d.read_struct_field(dataArray, 2) |d| {
let mut arr:~[u8] = ~[];
do d.read_seq |d, len| {
for i in range(0u, len) {
arr.push(d.read_seq_elt(i, |d| d.read_u8()));
}
}
arr
}
}
}

}
}

//second possibility to decode json is to implement the ToJson trait.
impl ToJson for TestStruct2 {
fn to_json( self ) - Json {
let mut d = ~TreeMap::new();
d.insert(~dataInt, self.dataInt.to_json());
d.insert(~dataStr, self.dataStr.to_json());
d.insert(~dataArray, self.dataArray.to_json());
Object(d)
}
}

fn Test2(){
//second possibility : use impl of to_json() to serialize
let test2 : TestStruct2 = TestStruct2 {dataInt: 1, dataStr:~toto, 
dataArray:~[2,3,4,5]}; 
//{\dataArray\:[2,3,4,5],\dataInt\:1,\dataStr\:\toto\}

let tjson : Json = test2.to_json();
let jsonStr:~str = tjson.to_str();
println!(Test 2 encoded using to_json {:?}, jsonStr);
assert_eq!(jsonStr, 
~{\dataArray\:[2,3,4,5],\dataInt\:1,\dataStr\:\toto\});


//unserialize using the our own impl of decoder
//convert the string to a json object and decode.
let mut decoder = Decoder(extra::json

[rust-dev] error: cannot move out of dereference of @ pointer

2013-11-20 Thread philippe . delrieu
I'am still testing the json lib and I try to encode the json using
extra::json::Encoder. The code I use is :
let mut encoder = extra::json::Encoder(m as @mut Writer);
test.encode(mut encoder);
let st:~[u8] = m.inner();

I have the error : error: cannot move out of dereference of @ pointer

the inner is declared as follow :
/// Because this takes `self' one could never 'undecorate' a Reader/Writer
/// that has been boxed. Is that ok? This feature is mostly useful for
/// extracting the buffer from MemWriter
fn inner(self) - T;

My second question is how to convert a ~[u8]  to a ~std ?

Philippe Delrieu

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


Re: [rust-dev] How to cast a @type in a @trait

2013-11-20 Thread philippe . delrieu
Selon Philippe Delrieu philippe.delr...@free.fr:

 Thanks you it works in my simple test but I have this error when I add
 it in my program : error: can't find crate for `std`
 I try to find why it doesn't work in my program and I found the error
 occurs when I add the extern mod zmq;.

 Perhaps I have to build lib zmq with the same flag.

I found the issue. I have to recompile zmq with the last version of rustc.
Extern lib link has changed in the current master trunk and the externfn! macro
disappeared. I have to update rust-zmq to make it compile.
I can send the modified file to the zmq maintener or pull the modif.

Philippe


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


Re: [rust-dev] Rust docs

2013-11-19 Thread Philippe Delrieu

Hello,

I would like to share my experience about the Rust doc and the tutorial. 
I've just started to learn Rust and I've decided to use it on a project 
I work on. Like everybody I read the Rust tutorial. It's not a really a 
tutorial for beginner but it do a good job in presenting Rust and its 
mains concept. I found other tutorial on the web and in my opinion what 
is missing the more is sample code. The Rust lib is huge and there is no 
code. In my project I have to use Json serialization. So I wanted to use 
the json lib in extra lib and I really spend some time to make a simple 
code works. I was very near to write my own lib. json.rs is a little 
complicated for a newbie. There are some test case at the end but it 
tests the lib and not what I want to do with it. For example there is no 
serialization of an object. I search the web and I found some old 
example (not compatible with the master lib) and no object serialization.


So what I think is that it would be great is to construct a repository 
of sample code of the Rust lib that show how to use the lib. I'm ok to 
write and maintain some sample like one on json. I think it would be 
great to host all these sample in the same repository and to have the 
same organization for all sample. The second reason tu use a share 
repository is that the sample has to be made in the spirit of Rust to 
help understand it. For that the sample must be checked and modified by 
more experienced rust developer. It's easier when the code is in a 
common repository.


Pḧilippe
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Rust docs

2013-11-19 Thread Philippe Delrieu

I'am ok to add sample code in json.rs.
how can I do?
I think I will have other sample code for other lib in a few days. I'll 
wait that the lib is open to doc enhancement or I put it as it come and 
how can it be managed.


Philippe

Le 19/11/2013 14:48, Gaetan a écrit :
Also, what we set up in our scrum team is targetted doc stories 
inside each sprint.


Let's say that over the next month, the objective is to improve a set 
of module doc, ie, a list of very useful std or extra lib that is not 
properly documented.
For instance, the next month we target on improving json or 
extra::path, and enhance them until they become golden star level. And 
the next month or sprint, we focus on other modules


It's easier to focus people like this that just telling you can take 
whichever module you want and improve them. It just work better, we 
discovered.


-
Gaetan



2013/11/19 Gaetan gae...@xeberon.net mailto:gae...@xeberon.net

I think it's better to enhance the extra::json lib itself and
write proper module documentation, with samples, use case etc.
My reference is the QT documentation. You never open and samples
or even the QT source code, everything is in the module documentation.

-
Gaetan



2013/11/19 Philippe Delrieu philippe.delr...@free.fr
mailto:philippe.delr...@free.fr

Hello,

I would like to share my experience about the Rust doc and the
tutorial. I've just started to learn Rust and I've decided to
use it on a project I work on. Like everybody I read the Rust
tutorial. It's not a really a tutorial for beginner but it do
a good job in presenting Rust and its mains concept. I found
other tutorial on the web and in my opinion what is missing
the more is sample code. The Rust lib is huge and there is no
code. In my project I have to use Json serialization. So I
wanted to use the json lib in extra lib and I really spend
some time to make a simple code works. I was very near to
write my own lib. json.rs http://json.rs is a little
complicated for a newbie. There are some test case at the end
but it tests the lib and not what I want to do with it. For
example there is no serialization of an object. I search the
web and I found some old example (not compatible with the
master lib) and no object serialization.

So what I think is that it would be great is to construct a
repository of sample code of the Rust lib that show how to use
the lib. I'm ok to write and maintain some sample like one on
json. I think it would be great to host all these sample in
the same repository and to have the same organization for all
sample. The second reason tu use a share repository is that
the sample has to be made in the spirit of Rust to help
understand it. For that the sample must be checked and
modified by more experienced rust developer. It's easier when
the code is in a common repository.

Pḧilippe

___
Rust-dev mailing list
Rust-dev@mozilla.org mailto: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


[rust-dev] How to cast a @type in a @trait

2013-11-19 Thread Philippe Delrieu
I still struggle with the json API. I try it using encode and decode API 
and I face a problem.

I take this code in the json test case :
let m = @mut MemWriter::new();
f(m as @mut io::Writer);
and I have an error :
The managed box syntax will be replaced by a library type, and a garbage 
collector is not yet implemented. Consider using the `std::rc::Rc` type 
for reference counted pointers.


With this error I can't use extra::json::Encoder that expect a @mut 
io::Writer


I use the master updated on the 15/10

Any idea.

I didn't see if the json test case compile. Rust build but I don't know 
if the test are compiled by default.


Philippe


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


[rust-dev] zmq and Rust task

2013-11-08 Thread Philippe Delrieu

Hello,

I don't know if it's the right place to ask but I didn't find any 
information on zmq side.
I found a strange behaviour using zmq rust binding. I start a task that 
loop and after I start another task that bind a port and way to receive 
a message. The zmq recv call block the first task that run only when the 
second task is receiving a message.


The only way I found is to use the ZMQ_NOBLOCK (1) flag but I found 
strange that a blocked task can block all other task.


I test on linux (Ubuntu 1204) with the master trunk of Rust (cloned on 
10/20/13) and the trunk of rust-zmq. My version of zmq is 3.2.4.


Any idea?

The code :

extern mod extra;
extern mod zmq;

use std::rt::io::timer;

#[main]
fn main() {
println(hello?);

do spawn ||{
loop {
 timer::sleep(500);
println(coucou);
}
}

do spawn || {
   let context = zmq::Context::new();
let responder = context.socket(zmq::REP).unwrap();

assert!(responder.bind(tcp://*:).is_ok());

let mut msg = zmq::Message::new();
loop {
responder.recv(mut msg, 0);
do msg.with_str |s| {
println!(Received {}, s);
}
responder.send_str(World, 0);
   timer::sleep(100);
}
}

timer::sleep(1);

}

Philippe Delrieu

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


Re: [rust-dev] Access error for trait implemtation in multiple file

2013-11-08 Thread Philippe Delrieu

hanks for your fast answer.
I've made some test and if I remove mod actions; in testaction.rs I have 
the error: unresolved name impl actions::Action for TestAction in 
testaction.rs
If I remove the mod actions; and keep the mod testaction; in the test.rs 
I have unresolved name in the line let actelm: ~actions::Action = 
element as ~actions::Action; for actions::Action.


I don't see what to do!!

I didn't fully understand the module management but even if I made 
something wrong rustc in my opinion shouldn't load the same module twice 
and if a module is load once it should use it for all. It make me think 
about I#ifndef in C.


Philippe Delrieu


Le 08/11/2013 09:53, Alex Crichton a écrit :

You should be careful to declare modules only once. It looks like you
have two instances of mod actions in the module hierarchy, and both
modules will be compiled as separate entities (although everything
will have the same name).

If you remove the `mod actions` inside of testaction.rs you should
start making some more progress. You'll probably hit some name
resolution issues, but just be sure to import the previous declaration
of the `actions` module in the top level of the crate.

On Thu, Nov 7, 2013 at 11:50 PM, Philippe Delrieu
philippe.delr...@free.fr wrote:

Hello, rust addict.

I have a problem with rustc. I have 3 files.
The first one actions.rs contains a trait declaration :

pub trait Action {
 // process the action on server side.
 fn process(self) - ~str;
}

The second contains a trait implementation testaction.rs:
mod actions;


pub struct TestAction{
 actiontype: uint
}

impl actions::Action for TestAction{

 fn process(self) - ~str {
 ~
 }
}
  The third test the trait cast :
 mod actions;
 mod midi;

 let element : ~testaction::TestAction =
~testaction::TestAction{actiontype:1};
 let actelm: ~actions::Action = element as ~actions::Action;
//error here
 println(process element : + actelm.process());
= generate  error: failed to find an implementation of trait

 let actelm: ~testaction::actions::Action = element as
~testaction::actions::Action;  //error here
 println(process element : + actelm.process());
= generate error: trait `Action` is inaccessible

If I put testaction content in the test file rustc compile.

Any idea?

Philippe Delrieu


___
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


Re: [rust-dev] zmq and Rust task

2013-11-08 Thread Philippe Delrieu
I found the problem. Rust schedules task in the same thread. If I stop 
the thread (the recv call sleep I think), every task stop.
So I read the doc and I see the spawn_sched method that start a new 
scheluder in a new thread.


I replace the do spawn with do 
std::task::spawn_sched(std::task::SingleThreaded) and now it work.


Philippe Delrieu


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


Re: [rust-dev] zmq and Rust task

2013-11-08 Thread Philippe Delrieu

Hi Erick,

thanks for your reply?

The spawn_sched work fine for me. You do a great job in the binding. 
Definitely it would be very good to have a zmq implementation in Rust 
but It's a lot of work and your binding seem good enough. I'll tell you 
if I found some problems.


best

Philippe Delrieu

Le 08/11/2013 14:38, Erick Tryzelaar a écrit :
(I maintain the bindings and this mailing list is fine for now. Bug 
reports work too)


Right now rust-zmq is a pretty straightforward binding of the zeromq 
library, and is not integrated with rust's scheduler. So it's not yet 
preventing the user from two tasks from deadlocking. The only safe way 
to deal with that is to spawn those tasks off in their own thread.


The best thing would be for us to write our own zmq implementation in 
rust, but that'll take quite a while to write. Or perhaps there is 
some way we can feed the ZMQ_FD of a socket to libuv to protect 
against task deadlocking.


On Friday, November 8, 2013, Philippe Delrieu wrote:

I found the problem. Rust schedules task in the same thread. If I
stop the thread (the recv call sleep I think), every task stop.
So I read the doc and I see the spawn_sched method that start a
new scheluder in a new thread.

I replace the do spawn with do
std::task::spawn_sched(std::task::SingleThreaded) and now it work.

Philippe Delrieu


___
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


Re: [rust-dev] Access error for trait implemtation in multiple file

2013-11-08 Thread Philippe Delrieu
I solve my problem by using absolute path every where. It's ok but I 
can't use the source file in another program with another root module.


Philippe Delrieu

I've read the tutorial



Le 08/11/2013 20:36, Alex Crichton a écrit :

I would recommend reading about Rust's module system at
http://static.rust-lang.org/doc/master/tutorial.html#crates-and-the-module-system
to get more familiar with how things work.

You may also want to read about how import statements work at
http://static.rust-lang.org/doc/master/rust.html#use-declarations to
get an idea of how to bring these names into scope.

In rust's module system, you don't really load modules per-se, but
rather insert them at certain points in the namespace hierarchy. It's
perfectly valid to insert the same module at multiple locations in the
hierarchy, but I agree that this may not always have the expected
behavior. This probably warrants a lint mode for this which is warn by
default about inserting the same file into the module hierarchy twice,



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


[rust-dev] Access error for trait implemtation in multiple file

2013-11-07 Thread Philippe Delrieu

Hello, rust addict.

I have a problem with rustc. I have 3 files.
The first one actions.rs contains a trait declaration :

pub trait Action {
// process the action on server side.
fn process(self) - ~str;
}

The second contains a trait implementation testaction.rs:
mod actions;


pub struct TestAction{
actiontype: uint
}

impl actions::Action for TestAction{

fn process(self) - ~str {
~
}
}
 The third test the trait cast :
mod actions;
mod midi;

let element : ~testaction::TestAction = 
~testaction::TestAction{actiontype:1};
let actelm: ~actions::Action = element as 
~actions::Action; //error here

println(process element : + actelm.process());
= generate  error: failed to find an implementation of trait

let actelm: ~testaction::actions::Action = element as 
~testaction::actions::Action;  //error here

println(process element : + actelm.process());
= generate error: trait `Action` is inaccessible

If I put testaction content in the test file rustc compile.

Any idea?

Philippe Delrieu


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