Re: [rust-dev] Destructuring and references

2014-11-10 Thread Vladimir Matveev
Hi, Daniel, Consider this example: let vec = vec![(1u, 2u)]; for (a, b) in vec.iter() { println!({}: {}, a, b); } a and b here are of type uint, which is implicitly copyable. It is not natural to take references to it when passing around its values. That is, variables under

Re: [rust-dev] String capitalization

2014-09-12 Thread Vladimir Matveev
Hi, Ollie, This variant is terser, but it could be even more readable if there were some kind of connect() for iterators. It surprised me that there is no such thing in Rust iterators. It would be possible to use some kind of interleave() for iterators for the same purpose, but there is no

Re: [rust-dev] Closures with owned environments

2014-09-09 Thread Vladimir Matveev
Hi, Allen! In fact, it is possible to do it now without DST, using unboxed closures only: #![feature(unboxed_closures, unboxed_closure_sugar)] fn make_adder(x: int) - Box|: int| - int { box |: y: int| x + y } fn main() { let f = make_adder(3); println!({}, f.call((4i,))); } Test

Re: [rust-dev] Is there a PNG lib?

2014-09-08 Thread Vladimir Matveev
Hi! These libraries may be interesting for you: * https://github.com/servo/rust-png * https://github.com/PistonDevelopers/rust-image It is also very simple to run external tools like ImageMagick from Rust. You will need Command [1] API for that. [1]:

Re: [rust-dev] Is there a PNG lib?

2014-09-08 Thread Vladimir Matveev
On Monday 8 September 2014 at 15:57, Vladimir Matveev wrote: Hi! These libraries may be interesting for you: * https://github.com/servo/rust-png * https://github.com/PistonDevelopers/rust-image It is also very simple to run external tools like ImageMagick from Rust. You will need Command [1

Re: [rust-dev] [ANN] Iobuf

2014-09-04 Thread Vladimir Matveev
Hi! I’ve noticed this piece of code in your library: #[inline] fn as_mut_slice(self) - mut [u8] { unsafe { match self { OwnedBuffer(ref v) = { let mut_v: mut Vecu8 = mem::transmute(v); mut_v.as_mut_slice() },

Re: [rust-dev] Implementing a clone trait on mut struct.

2014-08-04 Thread Vladimir Matveev
Forgot to send a copy to mailing list. 2014-08-04 10:30 GMT+04:00 Vladimir Matveev dpx.infin...@gmail.com: Hi, Paul, The problem with Clone implementation for mutable reference is not that it does not make sense at all; after all, it is just an integer value behind the fancy name

Re: [rust-dev] Rust Executable size

2014-07-11 Thread Vladimir Matveev
Hi, Adrian, Currently Rust uses static linking to build executables. This means that the simplest «hello world» program utilizing standard library will take all of this library and all dependent libraries, including Rust runtime, into itself. That’s why the binary is large. If you want to use

Re: [rust-dev] Cargo multiple targets

2014-07-02 Thread Vladimir Matveev
Hi, Isak! According to manifest documentation [1] you can specify crate type (dynamic or static lib or rlib) using crate_type option: [[lib]] … crate_type = [dylib, staticlib] The above configuration should build you both .a and .so files. [1]: http://crates.io/manifest.html, search for

Re: [rust-dev] Fwd: self/mut self in traits considered harmful(?)

2014-06-17 Thread Vladimir Matveev
Overloading Mul for matrix multiplication would be a mistake, since that operator does not act the same way multiplication acts for scalars. I think that one of the main reasons for overloading operators is not their genericity but their usage in the code. let a = Matrix::new(…); let

Re: [rust-dev] Porting a small DSP test from C++ to Rust: Comments and performance observations

2014-06-11 Thread Vladimir Matveev
Hi, Kevin! * What would be the replacement for a struct-scoped static constant, so I could put a static inside a struct instead of making it a global? It is not possible now. There are some suggestions on associated items, but I don’t think they are active. Currently Rust module system is

Re: [rust-dev] 7 high priority Rust libraries that need to be written

2014-06-10 Thread Vladimir Matveev
Well, JSR-310 is implemented here [1], and it is licensed under GPL2 license. As far as I remember, in that case Google reproduced some internal Java API, so this seems to be a different thing. BTW, one of the implementors of JSR-310 suggested [3] looking into an older implementation which is

Re: [rust-dev] Generic Database Bindings

2014-06-08 Thread Vladimir Matveev
There is also rustsqlite[1]. It would be great to have generic bindings for databases, like in Go or in Java. In Rust, however, reflective approaches of these won’t work because Rust lacks structural reflection. I guess, generic bindings will have to follow type classes approach, like

Re: [rust-dev] Deprecating rustpkg

2014-06-07 Thread Vladimir Matveev
Hi, Fredrik, Currently a new package manager designed specifically for Rust is under active development. It is called Cargo, and you can find it here [1]. It is pretty much in very alpha stage now, but one day it will become a full package manager and build system for Rust. [1]:

Re: [rust-dev] Passing arguments bu reference

2014-06-01 Thread Vladimir Matveev
Aw, Gmail makes it so easy to press Reply instead of Reply to all. See below :) Hi, Christophe, Because `Vec` looks like this: struct VecT { len: uint, cap: uint, data: *mut T } its actual size is just three words, so you can freely pass it around regardless of number of

Re: [rust-dev] failed to find an implementation of trait core::cmp::TotalEq for ~str

2014-05-31 Thread Vladimir Matveev
Hi, Christophe, You shouldn't be using `~str` at all, you should use `String`. Also, `box ` is not a replacement for `~`, they have different types. The proper replacement is `String::new()` or `.to_string(). Your code in modern Rust will look like this: /// Contains a list of properties. A

Re: [rust-dev] cannot borrow `st` as mutable more than once at a time

2014-05-30 Thread Vladimir Matveev
2014-05-30 5:37 GMT+04:00 Kevin Ballard ke...@sb.org: It shouldn't. The for-loop desugaring looks like match mut st.execute_query() { __i = loop { match __i.next() { None = break, Some(mut __value) = { let i = __value;

Re: [rust-dev] A few random questions

2014-05-29 Thread Vladimir Matveev
It happens even for this: struct Test { a: int } impl ToStr for Test { fn to_str(self) - String { self.a.to_str() } } As you can see, Test is not implementing Show, so I assumed that I could implement ToStr instead. I suspect that there is somewhere an implementation

Re: [rust-dev] cannot borrow `st` as mutable more than once at a time

2014-05-29 Thread Vladimir Matveev
Hi, Christophe, Won't wrapping the first `for` loop into curly braces help? I suspect this happens because of `for` loop desugaring, which kind of leaves the iterator created by `execute_query()` in scope (not really, but only for borrow checker). 2014-05-29 19:38 GMT+04:00 Christophe Pedretti

Re: [rust-dev] StrBuf and regular expressions

2014-05-26 Thread Vladimir Matveev
regexp on it). Urban On Mon, May 26, 2014 at 8:58 AM, Vladimir Matveev dpx.infin...@gmail.com wrote: My suspicion is that the automatic conversion will come back at some point, but I'm not sure. I think it will be possible to make `String` implement `Derefstr` when DST land

Re: [rust-dev] *c_char and *c_uchar

2014-05-10 Thread Vladimir Matveev
Hi! First of all, if you are writing custom bindings to sqlite not only to learn Rust, I'd suggest using already existing bindings [1]. That way you probably won't have to deal with low-level C integration stuff. However, if you want to learn how to write C bindings, you should probably start

Re: [rust-dev] 3 ways to do, which is the best one in terms of Rust philosophy ?

2014-05-10 Thread Vladimir Matveev
Christophe, Indeed, the idiomatic way is to use Result enum [1]. Note that you are not limited to IoResult, you can use any custom error type, for example, ResultT, 'static str. The documentation (a link to which is below) is very nice, it contains a lot of examples and use patterns. So, your

[rust-dev] References to trait objects are not cloneable

2014-05-03 Thread Vladimir Matveev
Hi all, I posted this question on [Stack Overflow][1], but it is yet to be answered there, so I ask here too. Why reference to traits are not cloneable? The following code compiles: struct Test; fn clone_vec'a(v: Vec'a Test) - Vec'a Test { v.clone() } But this one doesn't: trait Test {

Re: [rust-dev] Alternative to Option types

2014-02-28 Thread Vladimir Matveev
Hi, Tobias, Yes, there is. A monad is a functor by definition, so it has to accept a type to produce another type. It can't be represented in another way, at least in Haskell. You can't come up with a sensible definition of a functor without HKT: class Functor (f :: *) probably something else

Re: [rust-dev] Deprecating rustpkg

2014-02-03 Thread Vladimir Matveev
2014-02-02 Thomas Leonard tal...@gmail.com: [ I don't want to start another argument, but since you guys are discussing 0install, maybe I can provide some useful input... ] I don't follow this. Whether the developer uses 0install to get the build dependencies doesn't make any difference to

Re: [rust-dev] Deprecating rustpkg

2014-02-01 Thread Vladimir Matveev
Is it possible at all to find the latest version of a library which is still compatible completely automatically? Incompatibilites can be present on logic level, so the compilation wiith incompatible version will succeed, but the program will work incorrectly. I don't think that this can be solved

Re: [rust-dev] Deprecating rustpkg

2014-02-01 Thread Vladimir Matveev
You can do that within a major version, except for one case - multiple developers creating diverged versions of 2.13, based on 2.12, each with their own features. ... But doing it per major version recursively raises the question of which major version is authorised: what if you have a

Re: [rust-dev] Deprecating rustpkg

2014-02-01 Thread Vladimir Matveev
To clarify, when I was writing user I meant the developer who uses this package, not the end user of complete program. On 01/02/14 19:32, Vladimir Matveev wrote: When this API is used directly by the package, then the user *should* know about it. He's using it, after all

Re: [rust-dev] Avoiding partially moved values error when consuming a struct with multiple fields

2014-01-26 Thread Vladimir Matveev
{ let Test1 { a, b } = self; Test2 { c: a, d: b as f64 } } On Sun, Jan 26, 2014 at 9:32 AM, Vladimir Matveev dpx.infin...@gmail.com wrote: Hi all, Consider this code: struct Test1 { a: ~str, b: f32, } struct Test2

Re: [rust-dev] Lifetime help

2014-01-20 Thread Vladimir Matveev
() be sufficient? Or is it because of the lifetimes? On Jan 20, 2014 1:41 AM, Vladimir Matveev dpx.infin...@gmail.com wrote: Hi, In fact, you're almost there. You only need to add lifetime annotations on `Sprite` in the intermediate HashMap variable and in return type. See here: https

[rust-dev] Failure stacktraces

2014-01-19 Thread Vladimir Matveev
Hi, Is it possible to view full stacktraces when task fails? Currently only the last item in the stacktrace is printed to the terminal when I run a failing program. I'm very surprised that I was not able to find any information on this. It looks like that the problem is nonexistent. However, the

Re: [rust-dev] Failure stacktraces

2014-01-19 Thread Vladimir Matveev
, but we'd need to start parsing DWARF etc. Not trivial. On Sun, Jan 19, 2014 at 12:58 PM, Vladimir Matveev dpx.infin...@gmail.com wrote: Hi, Is it possible to view full stacktraces when task fails? Currently only the last item in the stacktrace is printed to the terminal when I run a failing

Re: [rust-dev] Lifetime help

2014-01-19 Thread Vladimir Matveev
Hi, In fact, you're almost there. You only need to add lifetime annotations on `Sprite` in the intermediate HashMap variable and in return type. See here: https://gist.github.com/dpx-infinity/8516387 I tried to emulate rust-sfml types. This gist compiles, and the test is successful. BTW, you

Re: [rust-dev] Exporting macros: #[macro_escape] usage

2014-01-11 Thread Vladimir Matveev
to the scoping rules of macros, you don't need #[macro_escape] there---it's a child, so it gets the macro. Only siblings, parents, uncles, aunts, cousins, c. would need it. On Jan 11, 2014 9:46 AM, Vladimir Matveev dpx.infin...@gmail.com wrote: Hi, As far as I understand, the current way

[rust-dev] Exporting macros: #[macro_escape] usage

2014-01-10 Thread Vladimir Matveev
Hi, As far as I understand, the current way to export macros is to annotate the module with macro_rules definition with #[macro_escape] annotation. But I just can't get it right, and my macro is not visible in other module :( Here is what I have: - START - /lib.rs:

Re: [rust-dev] Trait method self parameter type clashes with lifetime annotation required by the implementation

2013-09-29 Thread Vladimir Matveev
I think I should have put my code to gist to track changes easily. Amending: https://gist.github.com/dpx-infinity/6751843 2013/9/29 Vladimir Matveev dpx.infin...@gmail.com: Yes, this is what I have observed too, see issue https://github.com/mozilla/rust/issues/9597. I didn't know that using

Re: [rust-dev] Trait method self parameter type clashes with lifetime annotation required by the implementation

2013-09-29 Thread Vladimir Matveev
As far as I understand, you're mostly right, except the structures bit. Disregarding that it is not possible to use several lifetime parameters yet, I see only one slight mistake: `s: MyStruct'a` does not imply that `s` variable has any specific lifetime. If it is a local variable, then it has

[rust-dev] Trait method self parameter type clashes with lifetime annotation required by the implementation

2013-09-28 Thread Vladimir Matveev
Hi all, The problem I'm writing about in this message follows from the one I have described in my other message: https://mail.mozilla.org/pipermail/rust-dev/2013-August/005281.html . I believe I'm now able to formulate it more clearly. Consider the following example code: trait Walker { //

Re: [rust-dev] Borrowed pointers with lifetime in structures cause weird errors

2013-08-21 Thread Vladimir Matveev
continue to use internal iterators, you just don't get the `for` syntax anymore. Just write a higher-order function as you always did, possibly returning bool to indicate whether to break or continue. Niko On Sat, Aug 17, 2013 at 01:54:09PM +0400, Vladimir Matveev wrote: Hello, I'm

[rust-dev] Borrowed pointers with lifetime in structures cause weird errors

2013-08-17 Thread Vladimir Matveev
Hello, I'm writing a simple tokenizer which is defined by this trait: trait Tokenizer { fn next_token(mut self) - ~str; fn eof(self) - bool; } Obvious application for a tokenizer is splitting a stream going from Reader, so I have the following structure which should implement Tokenizer: