Last active
August 29, 2015 14:08
-
-
Save lifthrasiir/dcd09bdf4748b2f606e6 to your computer and use it in GitHub Desktop.
Short Q&A from #rust, mainly collecting my (Yurume's) answers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
09:25:37 < duncan> i know i am just doing something stupid, but I am getting a confusing error message trying to implement the Iterator trait: http://is.gd/48ZeJk | |
09:26:12 < duncan> on the same line, I get 2 opposing errors: "error: wrong number of lifetime parameters: expected 0, found 1" "error: wrong number of type arguments: expected 1, found 0" | |
09:26:24 < duncan> same line, same column | |
09:26:42 < Yurume> duncan: Iterator accepts a type parameter, not a lifetime parameter. | |
09:26:55 < Yurume> maybe you want `impl Iterator<uint> for ...` | |
13:54:50 < derek_c> I want to iterate through a Vec and remove the first element that satisfies a certain condition. how may I do so? | |
13:56:16 < Yurume> derek_c: vec.remove(vec.as_slice().iter().position(|&e| ...).unwrap()) | |
14:23:54 < bananasaur> if i don't need custom syntax is there any benefit to a macro over just inlining a function? | |
14:24:18 < Yurume> then prefer a simple function, it gives an additional type checking. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14:52:30 < zekesonxx> So if I want to use an enum like an enum, with the values representing u8s, how can I find the enum value given a u8? | |
14:52:55 < Yurume> rusti: enum A { x = 1, y = 4, z = 9 } z as uint // zekesonxx, did you mean this? | |
14:53:18 < zekesonxx> lol and no | |
14:53:40 < zekesonxx> Say I have the number 4 | |
14:53:45 < zekesonxx> I want to resolve that to y | |
14:56:35 < Yurume> rusti: #[deriving(Show,FromPrimitive)] enum A { X = 1, Y = 4, Z = 9 } fn to_a(x: uint) -> Option<A> { FromPrimitive::from_uint(x) } (to_a(4), to_a(5)) // zekesonxx, how about this? | |
14:56:37 -rusti:#rust- (Some(Y), None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10:03:32 < reem> Yurume: As in I want to have a 1-lookahead parser | |
10:03:39 < Yurume> use `Peekable`? | |
10:52:16 < blaenk> if you're writing a library, how do you handle those warnings about unused code, if you only use them in the tests? | |
10:52:39 < Yurume> #[cfg(test)] | |
11:56:47 < Guest59> What's the word on the macro notation? Is it being changed to @ sign? | |
11:57:24 < Yurume> Guest59: not yet determined. | |
14:19:46 < earlz_> would it be at all useful to support hmm.. like named tuples? Basically an inline way of declaring a temporary struct (foo: 1u, bar: 2u).foo | |
14:20:16 < Yurume> earlz_: Rust once had a structural type. it is determined that the nominal type is suitable for many things, it is now gone. | |
15:26:07 < derek_c> println doesn't print to stdout in a test, does it? | |
15:28:13 < Yurume> cargo test -- --nocapture | |
15:28:20 < Yurume> (note the bare `--`) | |
16:09:31 < iu> Hey everybody! Is there a trait for implicit conversion between two distinct types? | |
16:09:37 < Yurume> currently no. | |
16:09:54 < Sharp> Hopefully never… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
02:29:32 < earlz_> rusti: std::rand::random::<f64>() | |
02:29:33 -rusti:#rust- 0.986209 | |
02:29:40 < earlz_> how does that even work | |
02:29:58 < Yurume> earlz_, f64 implements a Rand trait. | |
02:30:25 < Yurume> std::rand::random is just a convenient wrappar around Rand | |
10:26:46 < coryforsyth> did the BigUint struct go away between 0.12.0 and nightly? I see it if I search in the 0.12.0 api docs, but not the nightly | |
10:27:06 < Yurume> coryforsyth: moved to num crate. | |
10:28:15 < coryforsyth> Yurume: is num crate now something separate that I need to download/install? | |
10:28:44 <@huon> coryforsyth: https://github.com/rust-lang/num#usage | |
10:54:07 < mrob> Is there any way to have a generic function on an integer literal, like with C++ non-type templates? | |
10:55:39 < mrob> Eg. fn multiply(val: int, T int_literal) -> int | |
10:56:58 < Yurume> integer static parameter is not there yet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
09:53:42 < awelkie> How can I set the type of Float::two_pi() without setting it to a variable? | |
09:54:29 < Yurume> awelkie, you can't, but you can use a direct expr `{ let twopi: f64 = Float::two_pi(); twopi }` | |
09:57:16 <@huon> Yurume: awelkie: I think the planned fully-explicit syntax is `<f64 as Float>::two_pi()` | |
09:57:30 <@huon> but abbreviations will work when unamgbious, e.g. <f64>::two_pi() | |
10:12:22 < mrob> How do I loop over an iter and get the index of each item? | |
10:13:30 < Yurume> mrob: enumerate. | |
10:15:37 < kurtis> so I was thinking about making an FTP client in Rust for fun. has anyone worked on something like that yet? I don't wanna repeat work. | |
10:16:14 < Yurume> kurtis: http://www.rust-ci.org/projects/ lists none | |
10:28:53 < MisterE> If I have struct S { x: [int, ..10000] } and fn new() -> S { ... }, can I know for sure if it's going to copy the whole struct when I call new? | |
10:30:01 < MisterE> (as in I'd like to avoid large copies) | |
10:32:06 < Yurume> MisterE: `fn new() -> S { let s = S { x: [0, ..10000] }; s }` won't copy, but you'd better not relying on that. | |
10:44:10 < kurtis> also, what's the <'a> thing I keep seeing? Can I read up on that somewere? | |
10:44:26 < Yurume> kurtis: sure, http://doc.rust-lang.org/guide-lifetimes.html | |
11:30:58 < petervaro> Hi! I need to write from a String from a given index to a to a File. I use the write_str() method for that, but how can I get a substring from my String object (from index to its end)? | |
11:31:35 < Yurume> petervaro: slice. | |
11:32:08 < Yurume> rusti: "foobarfoobar".to_string().slice(3, 9).to_string() | |
11:32:10 -rusti:#rust- barfoo | |
14:22:50 < ttttt> I'm sure this is a stupid question, but is there a simple way to generate a [u8, ..4] from a Vec<u8>? | |
14:23:35 < Yurume> ttttt: [v[0], v[1], v[2], v[3]] | |
14:23:41 < Yurume> sorry about that. :S | |
14:25:13 < ttttt> I'm storing mp3 frame headers and I thought it would be nice to represent the frame ID that way | |
14:26:00 < ttttt> I guess "id3v2.3 frame headers" | |
14:26:25 < Yurume> ttttt: how about read_be_u32() or similar. | |
14:27:35 < ttttt> Yurume: I could, but the docs for id3v2 are all given in terms of the ascii representation of the frame IDs | |
14:28:01 < Yurume> ttttt: also try https://github.com/rust-lang/fourcc | |
14:28:31 < Yurume> ttttt: so that you can use fourcc!("TIT1") instead of 0x54495431 | |
17:04:02 < iu> Hello. What is the standard approach for searching files in a directory by a pattern in Rust? | |
17:08:07 < Yurume> iu: sorry, that was `std::io::fs::readdir` | |
17:13:15 < ebfull> is there a way to make my FnMut sized? or some way to approach this? http://is.gd/7UnI69 | |
17:13:50 < Yurume> ebfull: box it. http://is.gd/wDYi0Z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment