« first day (931 days earlier)      last day (2550 days later) » 

8:55 AM
I wonder why this doesn't give a useful hint in this case.
Oh nevermind. It shows the hint on beta and nightly. Yeah :3
 
9:21 AM
I can't find a nice question about "How to modify self when trait restricts me to accepting &self in my method?". Maybe @Shepmaster is more successful in finding it? :P Otherwise I'd probably want to ask that question to have a clear question for marking others as duplicates. Or we could modify this recent question... not sure :/
 
@LukasKalbertodt You're right about RefCell, but I'd have liked to know more about where that Actor came from.
 
True... maybe we should ask OP...
 
Already did. ;)
An actor that can't inherently mutate its state sounds like a lame one.
Maybe the actor is shared between multiple message producers?
Because in this case there might be no other choice.
 
Mh maybe..
Is SO down for everyone right now? :P
 
9:47 AM
Seems ok from here.
 
10:17 AM
Should I turn my comment into an answer here...
 
10:33 AM
There.
 
11:08 AM
@E_net4 Nice. And you too were victim of the "accept-no-upvote-devil" :P At least you got mine now
 
@LukasKalbertodt You call it a demon? :|
 
@E_net4 Well... I just meant it happens often ;-)
 
TBH I don't care. Even the opposite (multiple votes w no accept) annoys me more, and I shouldn't care about that either. :)
 
I mean, I get that there are use cases for accept without upvoting. A really bad answer which regardless of the ugliness contains the solution for example...
Anyway I should do serious non-SO work now :<
 
@LukasKalbertodt That isn't always the case: this one of mine is seriously one of the best answers I have. Sometimes the OP just happens to be stubborn or not care after a while.
@LukasKalbertodt Indeed, you ought. I'm doing some aimless data mining over here...
Q: "How to shoot myself in the foot"
A: "You should not shoot yourself in the foot because it hurts. You can do that with X, but try Y Z instead"
OP: "But I want exactly to shoot myself in the foot. Here, I'm updating my question so it's clear that I want to."
A: *sigh*
 
12:06 PM
@LukasKalbertodt why you editing out use statements? :-)
 
12:34 PM
now SO is down
 
@E_net4 lol a lot of the time I want the best way of shooting myself in the foot
 
@Shepmaster I know I know :< That was a mistake. But I was really confused what exactly OPs question was. The error message they got should be easy to understand... so if they did understand that, they should have clarified that their question is about this given trait which can't be changed. But I gave up on that question, no time :<
 
1:01 PM
Yay SO is down.
 
 
2 hours later…
2:48 PM
are mozilla servers down?
irc and rust-lang just broke while nothing else broke
but they're back already... hmm
ah no, just the rust docs and playpen are down
 
The Rusty webs are collapsing!
 
and now reddit is gone
uhm
is my internet broken?
why is freenode and stackoverflow still on?
play.integer32.com also not reachable from here, but integer32.com is...
 
o_O
 
Sometimes it's not good to sit right on top of a major internet node
 
Access to Integer32's Playground is fine from here.
 
2:53 PM
yea, I'm assuming something local, but totally weird
 
 
5 hours later…
7:24 PM
How does one respond to this?
Normally I'd've just ignored but it feels rude to this time.
 
 
1 hour later…
8:52 PM
Heya
Anyone around?
 
@BernardoMeurer Hello!
 
@E_net4 Hey there!
use std::path;

mod probe {
    use std::fs;
    use std::path;
    pub fn files(dir: &path::Path, depth: u16) {
        let object_list = fs::read_dir(dir).unwrap();
        for object in object_list {
            let metadata = fs::metadata(object.unwrap().path()).unwrap();

            println!("Object: {}", object.unwrap().path().display());
        }
    }
}

fn main() {
    let src = path::Path::new("/home/meurer/test/a");
    let dst = path::Path::new("/home/meurer/test/b");
    probe::files(src, 0);
Why do I get "Use of moved value: object" at the println!?
 
What, is this a "please debug my code"? :o
I don't think we get those here very often... anyways, let me have a look then..
 
Nope, it's a what kind of error is this?
 
You used object when making metadata.
 
8:54 PM
I just started with rust
 
So you cannot use it again when printing.
 
How do I do this then? I don't want to thrash object just to get it's metadata
I mean, I shouldn't have to at least
 
That object binding should be of type io::Result<DirEntry> or similar. Make a new binding to object.unwrap().path() and pass a reference to both places.
That should be enough I guess.
 
@E_net4 What do you mean by "object binding"?
 
@BernardoMeurer It's what we call variables.
So when you do let a;, you just declared a binding.
 
9:02 PM
@E_net4 Ah, sweet, I got it to work
    pub fn files(dir: &path::Path, depth: u16) {
        let object_list = fs::read_dir(dir).unwrap();
        for object in object_list {
            let object_path = object.unwrap().path();
            let metadata = fs::metadata(&object_path).unwrap();

            println!("Object: {}", &object_path.display());
        }
    }
}
Like such
Nice!
 
That's right.
The part where you make that function handle errors is left as an exercise. ;)
 
@E_net4 Ah, that is something to do with unwrap, no?
I unwrap guarantees object isn't null
But I can do something else other than unwrap that properly handles the error instead of nuking the program?
Woohoo, docs!
@E_net4 If I have a type which is not Sized, such as path::Path can a function return a Vec of that?
 
@BernardoMeurer For the cases where the operations can fail, you may wish to return the error from the function, rather than panicking.
@BernardoMeurer The Error Handling part of the book will get you on the right foot.
@BernardoMeurer Vec in particular cannot hold objects of an unsized type. But you can avoid that in many ways, depending on how you want to approach it.
 
@E_net4 I see. All these functions should do is to iterate over a directory and register the files/folders found, and I wanted to return a vector with all the Paths
 
When the concrete type T: Path is known by the compiler, and all objects are of the same type, then you can return a Vec<T>.
 
9:13 PM
I was originally writing this in C++ with Boost, but I figured it was an opportunity to learn Rust
 
@BernardoMeurer In that case you're fine with Vec<PathBuf> because DirEntry.path() returns a PathBuf.
@BernardoMeurer Welcome aboard the Rust train. ;) I used to be a great C++ enthusiast myself some years ago.
I like how Rust addresses so many problem that easily sink into C++ programs.
 
@E_net4 Thanks :) I mostly use C, VHDL, and MIPS assembly lately, it's nice to experiment something nice like Rust
 
@BernardoMeurer Hmm, I also learned those 3 in my Bachelor's. It's a good idea not to stick with just what you learn in school.
 
9:29 PM
@E_net4 Is there no logical AND in Rust?
For doing things like if a && b
 
@BernardoMeurer IIRC you should try & instead.
 
            if (metadata.is_dir()) & (depth > 0){

            }
That works :)
Cool
 
9:44 PM
Hmm, this is weird
If I have a function like this pub fn files(dir: &path::Path, depth: u16) -> Vec<path::PathBuf>
And then in it I do something like such
let mut contained_files: Vec<path::PathBuf> = files(object_path.as_path(), depth - 1);
file_list.append(&contained_files);
error[E0308]: mismatched types
  --> src/main.rs:23:34
   |
23 |                 file_list.append(&contained_files);
   |                                  ^^^^^^^^^^^^^^^^ types differ in mutability
   |
   = note: expected type `&mut std::vec::Vec<std::path::PathBuf>`
              found type `&std::vec::Vec<std::path::PathBuf>`
   = help: here are some functions which might fulfill your needs:
           - .remove(...)
           - .swap_remove(...)
But Why are the types mismatches, both declarations are exactly the same
 
@BernardoMeurer You could try extend instead. append moves the elements from one vector to another, and you cannot move them from an immutable reference.
 
@E_net4 But I'd like to move I think, since after they are added to file_list I no longer need/want them in memory
 
@BernardoMeurer Then use extend. :) It can consume the second vector instead of mutating it into an empty vector.
 
@E_net4 Sweet, let me try :)
file_list.extend(files(object_path.as_path(), depth - 1));
@E_net4 Nice! I can do it in a single line even :)
 
 
1 hour later…
10:57 PM
Hmm
I'm having some issues understanding error handling
let object_list = fs::read_dir(dir).expect(format!("Failed to probe path {}", dir.display()).as_str());
Say I have something like this
That sucks because it's a long, hard to read line
How do I handle this properly?
What I don't get is how can I "unwrap it" but in a less convoluted way
 
Why is that red
 
Idunno
 
@Shepmaster It's blood rep, much like blood diamonds
 
@BernardoMeurer Do you really want to unwrap it? expect is just unwrap with a custom message.
 
@E_net4 I just want to make sure it's not None I guess, that's all unwrap/expect really do, right?
 
11:05 PM
@BernardoMeurer unwrap/expect makes sure that the whole program does not proceed if it's None.
 
@E_net4 Okay, yes, so what I want to do is to check that in a way where I can properly handle the error in case it does
Let me try something
 
@BernardoMeurer @E_net4 There's definitely &&
@набиячлэвэли I think it's fine to ignore ;-)
 
@Shepmaster Possibly. :>
 
& is bitwise AND
like 3 & 1 => 1
 
And Rust makes it work on bools apparently. :>
 
11:08 PM
@BernardoMeurer The types are not the same. A reference to a type is a different type, as is a mutable reference — T&T&mut T
@BernardoMeurer if you haven't seen it, the book is undergoing a big rewrite and has lots of great content — doc.rust-lang.org/nightly/book/second-edition
 
let object_list = fs::read_dir(dir){
    Err(err) => {
        println!("Failed to probe path {}", dir.display());
    },
    Ok(object_list) => object_list,
};
 
It has a section on error handling doc.rust-lang.org/nightly/book/second-edition/…
 
E.g. why is this bad code?
@Shepmaster I was about to say that the book is a bit klingon-ish, I will check the new version :)
 
whatis "this"? I'm missing context. :P
 
@BernardoMeurer Because it won't compile :-)
 
11:10 PM
@Shepmaster By bad I mean't broken :P
 
@BernardoMeurer Because it won't compile?
 
xD
 
@BernardoMeurer Namely object_list has no definition when an error occurs
 
Fair
Then how the heck do I catch an error here?
without unwrap/expect
 
11:12 PM
@BernardoMeurer it all depends on what you want to do in case of error
 
I want to print a friendly message and exit the program nicely
Because this just means the use gave us a bad path, and that's alright
"alright" - not bad enough we have to panic
 
So...
 
Most often you just raise all errors to the top, usually with try! or ?. This is explained in the book.
 
yeah
you'd return a Result from your function
and in your main you can do that match
and then if it was a failure, print something out
 
Ah, I see
Let me try :)
 
This is really weird for me
How am I returning my PathBuf Vector now?
If all I return is io::Result?
 
io::Result<Vec<Pathbuf>>
 
Oh god this is giving me a brainfuck
Do I really need to handle this like such?
Can I not just unwrap() and be done
This is such a PITA to do like this
 
11:32 PM
@BernardoMeurer Again, it depends on what you care to do
Panicking is fine
It just means that the user sees some text that says it panicked
 
@Shepmaster It just seems like it's too much boilerplate code
All I want is to display a text and quit :/
 
Really?
 
Well, I'm probably just being stupid
Because I really cannot understand how the hell to do this thing
Because right now I have this
 
Keep calm and you'll find an elegant way to do the work.
 
Is how I'd write (the part I'm aware you want)
 
11:37 PM
@Shepmaster Ah, that's the stuff!
 
What the
 
It doesn't do the directory filtering or recursive
 
That's the power of iterators, my friend.
 
(wasn't aware that was a goal)
 
11:39 PM
Well, I'm trying to write 3 functions
one that gets only directories
one that gets only files
and one that gets everything
 
I'd probably use a crate like crates.io/crates/walkdir
which handles the recurrence easily
but that's not fun for learning
 
@Shepmaster I don't want to use a crate for something this simple as well
Okay, I will leave the iterator magic for now
Let me look at that syntax
 
@BernardoMeurer Depends on what you consider "simple"
 
It took me 5 minutes to write it in C++, it's taking me forever in Rust (alas I started today, so that's expected )
 
I never mentioned this, but for someone who's used Java streams, Rust iterators will feel so familiar and right.
And if they were expecting easy parallelization... Meet rayon!
 
11:44 PM
The more I try to fix the redder my code becomes lol
I'm just rewriting this whole thing
@Shepmaster Okay, so I REALLY do not get this
/// Yields all directories in path up to depth
/// Passing a negative value means "unlimited" depth. Up to the limit of i32
pub fn directories(dir: &Path, depth: i32) -> io::Result<Vec<PathBuf>> {
    let object_list = fs::read_dir(dir)?;
    let mut dir_list: Vec<PathBuf> = Vec::new();
}
So on that first line there, how do I exit the function if an error happened?
Or do I not need to do that?
How do I even evaluate whether that was successful or not?
 
That is done automatically, because you used ?.
Before that, we had the try! macro, which would do something like if error, return error (out of function), else unwrapped outcome
 
Hey, that's pretty nice and easy to read!
I don't like this single-character automated brouhaha
So wait
How do I iterate over object_list now?
 
@BernardoMeurer Well, the try! macro still exists, feel free to give it a try. Although people usually prefer just the question mark.
 
@E_net4 I want to make this work with ? now, I need to understand this
 
Yep; ? was added because error propagation is such a integral part of Rust
 
11:56 PM
@BernardoMeurer Then it's what I said. :P Right now either one should work.
@BernardoMeurer Just... iterate? :P What do you wish to obtain?
 
WAIT
I think I got this
 

« first day (931 days earlier)      last day (2550 days later) »