« first day (932 days earlier)      last day (2539 days later) » 

12:02 AM
    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();

        for object in object_list{
            let object_path = object?.path();
            let metadata = fs::metadata(&object_path)?;
            if metadata.is_dir(){
                dir_list.push(object_path.to_path_buf());
                if depth != 0{
                    dir_list.extend(directories(object_path.as_path(), depth-1)?)
@E_net4 @Shepmaster Seems correct?
 
I'm not a compiler. :-(
 
@E_net4 Tsc, shame on you
 
@BernardoMeurer The only shame I have right now is still being awake.
 
let dir_list = probe::directories(src, 1);
How do I match on a declaration?
We're on the same time zone, so well
in fact we are on the same country
 
Doesn't change the fact that I've stuff to do tomorrow, and would like some proper rest. ;)
I'm pretty sure you can handle yourself there. Keep checking on Rust resources, search for SO questions, etc. I'm off. G'night.
 
12:06 AM
@E_net4 Thanks for all the help! Goodnight!
 
@BernardoMeurer play.integer32.com/…
Probably where I'd end up
(I'm helping cook so popping in and out)
 
@Shepmaster Over in main, how do you do that match if I want to assign the Vec in my Result to a variable?
If an error happens I know to call process::exit
 
12:21 AM
IT WORKS
YAS
    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();

        for object in object_list{
            let object_path = object?.path();
            let metadata = fs::metadata(&object_path)?;
            if metadata.is_dir(){
                dir_list.push(object_path.to_path_buf());
                if depth != 0{
                    dir_list.extend(directories(object_path.as_path(), depth-1)?)
let dir_list = match probe::directories(src, 1){
    Ok(f)=>f,
    Err(e)=>{
        println!("Error: {}", e);
        std::process::exit(1);
    },
};
 
right; process::exit is known to never return.
it's a "divergent function"
 
@Shepmaster I tried packing the print and exit in a function but then the compiler complained
about differing types on the match
 
So the type checker can ignore that branch when making sure that all of the match... match
you can mark your own function as diverging
fn foo() -> ! { ... }
 
Ah, nice
Can my function receive a general error?
I wanted a softQuit function that receives an error, prints and quits
 
what would "a general error" mean to you?
idiomatic Rust uses snake_case identifiers; so you want soft_quit
 
12:33 AM
@Shepmaster I think it's better if it just receives a String
Now I'm having a hard time getting the string out of io::Error
Fixed the naming :)
 
@BernardoMeurer Rust has generics and a std::error::Error trait, which is likely what you mean
 
@Shepmaster Yeah, I saw that, but I just need the Error message really
For soft_quit at least
Issue is getting that error message out of io::error
because supposedly it has a description trait
Oh
 
description is a method from a trait
so error.description() should work
 
Rust no method named description` found for type std::io::Error in the current scope`
I get this if I try that
let dir_list = match probe::directories(src, 1){
    Ok(f)=>f,
    Err(e)=>soft_quit(e.description()),
};
Ah!
I gotta add it
 
there should be compiler messages telling you to bring the trait in scope?
 
12:43 AM
Yep
I got it
But this isn't the same as I had before :/
Same message that is
Err(e)=>soft_quit(format!("{}",e)),
Ended up doing this
Kind of janky
 
e.to_string() is shorter
 
@Shepmaster Ah, sweet :)
@Shepmaster If I'm making a larger project, with many modules
Should each module live in it's own file?
 
1:03 AM
@BernardoMeurer If you mean a Rust module (mod foo), then almost always
the main exception to that would be unit tests
which usually live in mod test { ... } at the bottom of each file
 
@Shepmaster I do, yeah, do you have an example on this?
I want to see how Cargo.toml will look
and how do I import the "local" mods
 
Cargo toml wont change
TL;DR: `mod foo` will look for a `foo.rs` in the same directory or a `foo/mod.rs` (for
when you want to nest modules)
 
So wait
I have my mod probe
with it's functions and so on
I move it onto probe.rs in src/
And now at main.rs how do I "import" it?
use?
OH
I don't need the mod probe
 
1:26 AM
Heading for bed now
@Shepmaster Thanks for all the help!
 
1:40 AM
o/
 
 
6 hours later…
8:15 AM
@Shepmaster Interesting!
 
8:53 AM
I'm green, da-ba-de-da-ba-dahe.
 
 
1 hour later…
9:54 AM
More on the series of "Trust me, I'm an engineer!".
 
10:47 AM
@E_net4 That one is fine. The release method sounds scarier
 
@oli_obk-ker Are you implying that inducing a memory leak in safe code is ok? o_o
release is just as bad, and might result in UB if the bindings don't check things.
 
@E_net4: inducing a memory leak in safe code is ok
Perfectly fine
std::mem::forget does just that
it's safe and stable
you can implement it trivially by creating an Rc<RefCell<Struct>> cycle
 
Sad face.
 
@E_net4: safe code just mean safe. Memory leaks are not unsafe, but annoying. So there's other ways to prevent them than to make something like forget unsafe
We're trying to create lints that find memory leaks statically where possible
also with miri you can get really precise info about memory leaks
 
@oli_obk-ker Admittedly, I used to wonder why forget was not unsafe, but now I forgot why.
 
10:55 AM
@E_net4: the reason was exactly because you can implement it in safe code using Rc cycles
 
@oli_obk-ker But two wrongs don't make a right. :(
 
@E_net4: well... think about it this way: you can't create unsafety by leaking memory
thus, leaking memory is safe
Rc cycles are just one example of a memory leak, there are many other ways.
If it's trivially possible in safe code, the operation must be safe, because otherwise you'd be able to do unsafe stuff in safe code
 
@E_net4 Hey there :)
 
@oli_obk-ker That feels more an XY problem than anything... But I'll consent.
@BernardoMeurer Good day.
 
@E_net4 I have more questions on error propagation :P
 
10:59 AM
@BernardoMeurer Sorry, lunch time.
 
Dangit
 
@E_net4: You are focusing too much on my Rc-Cycles -> safe forget explanation. The actual reason is the part that you can't create unsafety by leaking memory
 
Ask @oli_obk-ker :P
 
@oli_obk-ker Can I bother you? :P
 
11:00 AM
sure, not sure if I can help though :P
 
Nice, so suppose I have a function like this
/// Yields all directories in path up to depth
/// Passing a negative depth value means "unlimited" depth, up to the limit of i32
pub fn directories(dir: &Path, depth: i32) -> Result<Vec<PathBuf>>
Over in main I used to handle it's errors like such
let dir_list = match probe::directories(src, -1) {
    Ok(f) => f,
    Err(e) => soft_quit(e.to_string()),
};
Where soft_quit() is a divergent function
 
Now, say I want a function that gives me a list of changed folders
I structure it like such
pub fn changed(src: &Path, dst: &Path, depth: i32) -> Result<Vec<PathBuf>>
(The idea is you have mirrored directories, and you want to check for changes on the source)
In it I can create my file lists like such
let src_files = files(src, depth);
let dst_files = files(dst, depth);
Here files() is the same as directories pretty much, except it yield a list of files, not directories (i.e. different filtering)
How can I handle errors here though?
I don't want to match inside my function, so I want to propagate the errors to whoever called it
 
@BernardoMeurer just write a ? after the function call ;)
 
@oli_obk-ker Oh wait, the problem had nothing to do with this :P
pub fn changed(src: &Path, dst: &Path, depth: i32) -> Result<Vec<PathBuf>> {
    let changed_files: Vec<PathBuf> = Vec::new();
    let src_files = files(src, depth)?;
    let dst_files = files(dst, depth)?;
    for copy in dst_files{
        for orig in src_files{
            println!("Foo");
        }
    }
    Ok(changed_files)
}
Why the heck do I get "use of moved value" on the second for?
And only on the second
 
11:07 AM
@BernardoMeurer because you are consuming it?
and you consume it in the first iteration of the outer loop
so it's gone in the second iteration
 
Ah, iterating consumes it?
Guess I can just do &src_files then
 
yea, but you can just slap an ampersand before src_files and it won't consume
exactly!
 
Okay, sweet :)
Slowly starting to be less dumb in Rust :P
 
@BernardoMeurer: good thing is, your code won't run until it's mostly right ;)
 
@oli_obk-ker I like VHDL more, your code will run even if it literally explodes the hardware
 
11:11 AM
mwhaha
 
@oli_obk-ker Is there a handy way to compare ` std::time::SystemTime` to check which one is newer?
 
I would imagine that impending Ord.
 
11:27 AM
fn is_newer(src: &fs::Metadata, dst: &fs::Metadata) -> Result<bool>{
    let src_time = src.modified()?;
    let dst_time = dst.modified()?;
    let mut newer = false;
    if src_time > dst_time {
        newer = true;
    }
    Ok(newer)
}
@E_net4 I ended up writing that
 
11:51 AM
@BernardoMeurer: you might want to get rid of newer and the if and write Ok(src_time > dst_time)
@BernardoMeurer: note that clippy would probably tell you something along those lines ;)
 
@BernardoMeurer you should also note how my solution accepted an Option<u32> instead of an i32
Using "negative values mean special things" is not really idiomatic
 
 
1 hour later…
1:25 PM
@E_net4 I like the mental image of an impending Ord
@oli_obk-ker At the very least it should be let newer = src_time > dst_time
 
@Shepmaster Ouch, only noticed that now. Damn swype.
 
 
1 hour later…
2:58 PM
Okay, I'm back
@Shepmaster Nice idea regarding using Option
I just made the changes :)
 
3:14 PM
@Shep will it blend? It's quite roughly a dupe of this one.
 
@E_net4 What were you saying about Ord?
 
@E_net4 Seems just different enough; you wanna answer it?
Or leave it to me to get even more sweet points
 
@Shepmaster I'm on it, although I'm not 100% sure.
 
@E_net4 tl;dr T &T and &mut T are all distinct types
so impl for T could mean &U (sometimes using two different types helps)
 
Ouch, conflicting ideas!
Wouldn't the problem be the same for a private trait? Unless the compiler does some darkemagick I don't know of.
Hah, a recommendation question?
 
3:29 PM
@E_net4 yea, you can't have two impl ... for T {}
 
Fair enough.
 
I think the important bit is the "says any type T implementing Hash"
and the distinct types, as I mentioned a bit above
people don't think that for T can actually mean for &u8
 
Heck, is C++/Rust a new language now?
 
@E_net4 lolwat?
 
0
Q: Keeping column names straight when indexing a wide std::array/vector in Rust or C++

krishnabI am developing some agent-based models in python, but have to offload some of the processing to Rust or C++ for speed. I have already profiled the code, so I know where the bottlenecks are. The problem is that I use pandas in python, and I have dataframes with about 50 columns or more--because I...

 
3:33 PM
Ah ^^
 
> I still get the error. Is there a reason for that
yup, they didn't get that &u8 is a T
 
Arguably my explanation could be more detailed. But whether it would be better with more details is questionable
I love how the Ada reddit has a post about porting surface to air missile systems from Ada to C++
 
3:54 PM
I killed the question. \o/
 
murderer!
 
@oli_obk-ker Chill, I'm kidding. I suggested the OP to narrow the problem down and they decided to start over.
 
I know ;)
 
\o/
 
 
3 hours later…
6:54 PM
@E_net4 is on fire today
 
7:15 PM
@Shepmaster HELP STOP DROP AND ROLL
I don't know what you mean. :P
 
7:29 PM
@E_net4 You beat me to answering two questions
although oli_obk-ker beat you as well ;-)
 
7:46 PM
@Shepmaster Do you mind answering a general algorithms question?
 
@BernardoMeurer Mind no; I may not be able to
 
@Shepmaster It's fairly simple I believe, here's what I have in mind
So, yesterday I (we) managed to write those 3 functions, that get all dirs, all files, or all objects (everything) in a given path
I was thinking of how, now to, given a source path and a destination path, to check which files in source are also in destination BUT have a newer modification date. So, basically, supposed dir A and B are "synced", A is source. Then I make a change to a file in A. What's the fastest way of checking that there is a file in A who also exists in B but who has been changed
Both the object lists, dir lists, file lists, whatever, are all sorted
 
8:03 PM
I don't know about fastest
but since the lists are sorted, you can walk them in tandem and compare the timestamps
you could eschew the lists and make them into sets, then take the intersection
mmm
you'd need to have a common way to do the sets though
like /foo/a and /bar/a map to the "same file"
 
 
3 hours later…
10:38 PM
I wonder if we already have a crate that derives builders.
Hah, there sure is: derive_builder :-)
I could see this coming once 1.1 macros became stable.
 

« first day (932 days earlier)      last day (2539 days later) »