« first day (19 days earlier)      last day (3476 days later) » 

12:42 PM
R U S T    R O C K S ! ;)
@R.MartinhoFernandes hey-hey!
 
1:04 PM
I gtg now -- but be back later ;)
(I just go grab something to eat)
btw which one is considered to be idiomatic-rust:
let str1 = String::from_str("chars");
let str2 = "chars".to_string();
 
I've seen the second one more often, and is the one I prefer.
 
2:10 PM
@R.MartinhoFernandes hmm.. at least it is shorter;)
I wish there were a literal syntax for that, something like: S"chars"
(on the other hand, that would be confusing, as it is dynamically allocated.. who knows..?)
 
2:38 PM
@PeterVaro Yeah, I prefer the explicitness.
 
btw @R.MartinhoFernandes are there any truly up-to-date benchmarks of Rust compared to C and C++ ?
because all I found was from 2012 and 2013 -- but since then the language changed a lot
 
I have no idea.
 
I see.. well, okay, thanks :)
 
 
2 hours later…
4:31 PM
hmm.. another interesting question.. (maybe only for me :P)
struct MyStruct {v: f64}
fn main() {
    let mut x = box MyStruct {v: 12.0};
    *x = MyStruct {v: 56.0};
}
this is valid, and it is okay to do this (ofc, I can change the value, I don't have to assign the "whole struct" again)
why would anyone wants to do this instead:
fn main() {
    let mut x = box MyStruct {v: 12.0};
    x = box MyStruct {v: 56.0};
}
(I'm asking because there are a few examples of the latter in the lifetime-guide)
 
4:51 PM
(I know, that the latter is allocating a new space in memory for a new MyStruct and frees the old one automatically.. but still :))
 
I think that only makes sense as an example to demonstrate that behaviour.
I can see it happening in more complex scenarios, but they wouldn't be fit for a small example.
 
 
4 hours later…
8:51 PM
@R.MartinhoFernandes just a quick question -- is this the correct way to open and read a file and print its contents? is it considered to be idiomatic?
use std::io::File;
use std::str;


fn main() {
    match File::open(&Path::new("src/main.rs")).read_to_end() {
        Ok(array) => match str::from_utf8(array.as_slice()) {
            Some(text) => println!("{}", text),
            None       => println!("Oh, snap!"),
        },
        Err(_)    => println!("We are screwed!"),
    }
}
 

« first day (19 days earlier)      last day (3476 days later) »