|
Double post, am I doing Rust right if almost all my mods end up being "pub mod"? Not sure how to expose, e.g., a crate one mod exposes without at least making it pub.
|
# ? Jan 2, 2018 06:11 |
|
|
# ? May 28, 2024 14:27 |
|
Beamed posted:Double post, am I doing Rust right if almost all my mods end up being "pub mod"? Not sure how to expose, e.g., a crate one mod exposes without at least making it pub. External crates are almost always put in lib.rs/main.rs. The only real exceptions are generated code that can't always rely on a dependency being available in a given location (and thus generate an extern crate declaration in the generated block).
|
# ? Jan 2, 2018 06:15 |
|
Linear Zoetrope posted:External crates are almost always put in lib.rs/main.rs. The only real exceptions are generated code that can't always rely on a dependency being available in a given location (and thus generate an extern crate declaration in the generated block). Which raises my question, I guess - I have extern crates which bring in dependencies for my controller/views on a given platform, but ideally later I'll have a second controller available with completely different dependencies. Things are definitely much nicer if I reference these in main for now, but I'd ideally like platform-specific view/controller to go to the specific controller, and so only bring in crates there. Guess it's a matter of if I care enough to create wrappers for those dependencies, huh..
|
# ? Jan 2, 2018 06:25 |
|
Beamed posted:Which raises my question, I guess - I have extern crates which bring in dependencies for my controller/views on a given platform, but ideally later I'll have a second controller available with completely different dependencies. Things are definitely much nicer if I reference these in main for now, but I'd ideally like platform-specific view/controller to go to the specific controller, and so only bring in crates there. Guess it's a matter of if I care enough to create wrappers for those dependencies, huh.. I mean, you can do that, you just have to make sure that the crate is only referenced in child crates of the one you import it from. No need for pub then. Something like code:
|
# ? Jan 2, 2018 06:39 |
|
Relatedly, in that type of situation I like to docode:
|
# ? Jan 2, 2018 08:18 |
|
Linear Zoetrope posted:I mean, you can do that, you just have to make sure that the crate is only referenced in child crates of the one you import it from. No need for pub then. Ralith posted:Relatedly, in that type of situation I like to do Oh wow, this is perfect. Thanks guys!
|
# ? Jan 4, 2018 08:02 |
|
The Rust youtube channel has just uploaded a bunch of lectures from some recent conference called Fosdem: https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA/videos
|
# ? Feb 6, 2018 13:19 |
|
Love Stole the Day posted:The Rust youtube channel has just uploaded a bunch of lectures from some recent conference called Fosdem: https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA/videos https://www.youtube.com/watch?v=fJ-6wsn1bZg "Qt GUIs with Rust" gives me hope for Rust GUIs. I'm currently using Gtk-rs for something I'd rather do with Piston/Conrod, because I couldn't get any of the Glutin/SDL2 based Piston windows to load on Intel Graphics. Also on a different machine, drawing bitmap textures was giving me weirdly desaturated colors, but drawing the same thing with GDK Pixbufs works just fine. Glad to see Qt up and coming as another option for Rust, even though this guy's approach still involves a bit of C++/JSON boilerplate.
|
# ? Feb 10, 2018 04:52 |
|
So am I missing something with the IntelliJ plugin? Tried it out again after everyone raved about it, but it still forces me to run cargo manually to see if I have any compiler errors. Do I accidentally have a setting that removes IntelliJ's underlining compiler/syntax errors or something? VS Code is still pretty cool but I miss the heavy IDE stuff sometimes.
|
# ? Feb 10, 2018 22:58 |
|
I've had similar experiences with IntelliJ. At least recent versions of the Rust plugin seem to have memory leaks and slowdowns, and it doesn't show all the errors or do proper syntax completion from crates. It's been a while since I tried Sublime Text with Rust, but IIRC that actually worked better with inline error checking.
|
# ? Feb 10, 2018 23:36 |
|
Beamed posted:So am I missing something with the IntelliJ plugin? Tried it out again after everyone raved about it, but it still forces me to run cargo manually to see if I have any compiler errors. Do I accidentally have a setting that removes IntelliJ's underlining compiler/syntax errors or something? I only get some, but not all, errors showing up inside of IntelliJ. Like it’ll usually catch typos and most type mismatches, but I don’t think it’s ever caught borrow checker issues without invoking the compiler.
|
# ? Feb 11, 2018 01:27 |
|
Beamed posted:So am I missing something with the IntelliJ plugin? Tried it out again after everyone raved about it, but it still forces me to run cargo manually to see if I have any compiler errors. Do I accidentally have a setting that removes IntelliJ's underlining compiler/syntax errors or something? Ditto. I’ve settled into a good workflow with Sublime Text and the RustEnhanced plugin. It’ll be nice once JetBrains has a full IDE though.
|
# ? Feb 11, 2018 01:46 |
|
I've loved intellij's support but it's not entirely cargo free no. Still a million times better than vs code and RLS though.
|
# ? Feb 12, 2018 10:14 |
|
gonadic io posted:I've loved intellij's support but it's not entirely cargo free no. VS code shows me compiler/syntax errors immediately, lets me ctrl+click into library code to read some APIs, in-built terminal, and is pretty. Am I missing something from IntelliJ that provides me even the first? Honestly asking because I really felt like I was missing something.
|
# ? Feb 13, 2018 06:57 |
|
gonadic io posted:I've loved intellij's support but it's not entirely cargo free no. Visual debugging seems to work very well in VS Code.
|
# ? Feb 13, 2018 07:23 |
|
Programming Rust is in the latest Humble Bundle, FYI.
|
# ? Feb 13, 2018 15:12 |
|
Beamed posted:VS code shows me compiler/syntax errors immediately, quote:lets me ctrl+click into library code to read some APIs, quote:in-built terminal i have no doubt that RLS will be the way to go eventually but it wasn't there last time I tried it (admittedly, around 6 months ago, haven't been doing much rust lately). DONT THREAD ON ME fucked around with this message at 02:50 on Feb 14, 2018 |
# ? Feb 14, 2018 02:38 |
|
MALE SHOEGAZE posted:??? this definitely works for me. Maybe RLS + VSCode is better but I've never had it not just continually crash on me so I'm not sure what it's like. Nope, don't get this. FAKEDIT: By the time I finished adding that to imgur and writing this post, it finally showed a red line. That.. I dunno, took awhile to recognize when I added the semicolon too. Doesn't spot the type error, either way. MALE SHOEGAZE posted:
Didn't say that IntelliJ didn't have these features, just meant to say VSCode supports the most necessary things pretty quickly. REALEDIT: Perhaps ironically, I feel like IntelliJ will be the way to go in the future; the more fully fleshed out features it provides will be better than I think RLS will support.
|
# ? Feb 14, 2018 04:32 |
|
Beamed posted:Nope, don't get this. That's weird friend, I dunno. Works on my machine, I guess!
|
# ? Feb 14, 2018 05:00 |
|
MALE SHOEGAZE posted:That's weird friend, I dunno. Works on my machine, I guess! Yeah, it's good to know that I am just missing something, haha.
|
# ? Feb 14, 2018 05:40 |
|
Subjunctive posted:Programming Rust is in the latest Humble Bundle, FYI. I've written libraries in Rust since 1.0 and this book taught me a lot, just halfway through reading it.
|
# ? Feb 14, 2018 08:04 |
|
Has anyone else had issues getting std::fs::remove_dir_all working on Windows? I get OS error 5 by doing something as simple as creating a directory tree and trying to remove it. I've been resorting to a #[cfg(windows)] patch function that just delegates to spawning a command running rmdir but that's obviously not... ideal. Edit: I figured it out, I was using the created tree to clone a git repository into and git was setting permissions weirdly. Had to use walkdir to manually set the cloned files to not be readonly . Linear Zoetrope fucked around with this message at 04:19 on Feb 21, 2018 |
# ? Feb 21, 2018 03:49 |
|
Github recently removed TLS 1.0 and 1.1 support. Windows 7's default behavior is not to support anything past TLS 1.0 The combination breaks cargo for a while, unless you install a patch. Microsoft Article They're currently working on making the generated error more descriptive of this particular issue. https://github.com/rust-lang/cargo/issues/5066
|
# ? Feb 28, 2018 16:32 |
|
If you’re still not able to support TLS 1.1 or up you bloody well deserve to be left behind. Especially when you’re trying to be a “modern” packaging system
|
# ? Feb 28, 2018 22:07 |
|
It's not that it can't, it's that the defaults that Windows 7 supplies, even after installing the system update to support recent tls versions, does not actually enable it. https://github.com/libgit2/libgit2/issues/4546 https://github.com/libgit2/libgit2/pull/4550
|
# ? Feb 28, 2018 22:51 |
|
geonetix posted:If you’re still not able to support TLS 1.1 or up you bloody well deserve to be left behind. Especially when you’re trying to be a “modern” packaging system This is correct when you replace "packaging system" with "operating system"
|
# ? Feb 28, 2018 23:08 |
|
I think when an OS's mainstream support period has ended you can safely say it's no longer trying to be a modern OS.
|
# ? Mar 1, 2018 06:13 |
|
I'm learning Rust and the borrow checker is beating me. I want to return a struct from a function, where the struct owns Stdout and StdoutLock objects that live as long as the struct itself. I'm pretty sure this means I need to heap-allocate the stdout objects, so Box needs to be involved somehow. Can someone help me understand what I need to do to get this to work?code:
code:
code:
|
# ? Mar 14, 2018 05:06 |
|
EkardNT posted:I'm learning Rust and the borrow checker is beating me. I want to return a struct from a function, where the struct owns Stdout and StdoutLock objects that live as long as the struct itself. I'm pretty sure this means I need to heap-allocate the stdout objects, so Box needs to be involved somehow. Can someone help me understand what I need to do to get this to work? Are you sure you need the Lock? You can write to Stdout directly, it just might get interleaved if another part of your program is also writing to it. Is this a concern? I'm not sure how to do this with StdoutLock, but if you only need Stdout, you don't need to Box it.
|
# ? Mar 15, 2018 04:06 |
|
alternatively, make the thing you plan to pass OutputDest to generic for any std::io::Write instead
|
# ? Mar 15, 2018 04:17 |
|
Yo dudes; learning Rust, and struggling with the borrow checker and unexpected ungulates. Code: Rust code:
code:
code:
|
# ? Mar 16, 2018 11:55 |
|
The example works because the type of "after" is inferred, so it just is a Cow<str>. In your code, "result" has the type &String, which is inferred from where it's initialized, so you can't just assign the Cow to it. And matching isn't helping because Cow holds either a &str, which you'd have to turn into a new String, or else a String that is about to be dropped after the current iteration of the for loop ends. The problem is that "result" can't refer to something it is going to outlive. Basically, you should change result to be a String itself because something has to actually own the intermediate, partially processed strings. When updating result, you could just blindly call into_owned() on the Cow from replace_all(). But this is wasteful as it will create a new String even when nothing got replaced, ie, when the Cow is Borrowed. So you can ignore that case and only look at when Cow is Owned, in which case you can just move from the String it holds: code:
|
# ? Mar 16, 2018 14:48 |
|
Thank you; that explanation and code sorted it out entirely; needed to dissect the cow. Related: Now I'm tackling out the uppercase-conversion (Replaced by "test" in my previous example. After changing the tail_letters iterator to chars instead of strings, this works: code:
code:
code:
code:
Dominoes fucked around with this message at 00:39 on Mar 17, 2018 |
# ? Mar 16, 2018 23:47 |
|
edit because I was wrong about this. But I think you are dealing with 3 different types. Count the `&` in each sample.
|
# ? Mar 17, 2018 00:56 |
|
I'm counting one in each, excluding the type annotation. Ie to convert a String, as output by char.to_string(), to a &str, as required by re.replace_all.
Dominoes fucked around with this message at 01:19 on Mar 17, 2018 |
# ? Mar 17, 2018 01:17 |
Dominoes posted:Why do I need to explicitly declare &str in this case? Shouldn't applying & automatically do that? &replacement could be a &str or a &String (or a &&str or a &&String etc), and if this is the only time you use replacement rustc doesn't know which one to infer it as. Looking at the docs for the regex crate, it looks like the signature for replace_all is generic in its second parameter: pre:pub fn replace_all<'t, R: Replacer>( &self, text: &'t str, rep: R ) -> Cow<'t, str> I think this may be intentional, since in the future someone could theoretically go add an impl of Replacer for String (or add an impl of FnMut(&Captures) -> String for String), which would cause your code to break. So my guess is Rust purposefully makes you type out the type here for that reason.
|
|
# ? Mar 17, 2018 01:18 |
|
Thanks Viking - that makes sense!
|
# ? Mar 18, 2018 09:11 |
|
So, I'm an idiot and need help. I want to get an array of length 64 of ChessCell objects. This should be really simple but it keeps giving compilation errors. code:
I'm kinda used to functional programming so I also tried to: 1) make an array [0,1, 2, ..., 63] 2) apply a function to each value in the array (map) 3) put the result of this .map(f) in an array with the same fixed size I'd expect this to be possible, but I'm having trouble with each of these three steps.
|
# ? Mar 30, 2018 00:18 |
|
I've spent the last two evenings looking at how to migrate a reasonably complex Rust system from error_chain to the new failure crate. The system uses a bunch of external libraries (e.g. r2d2_postgres, rouille, serde of course, ...) and previously we used error_chain's foreign_links functionality to explicitly declare how all the possible errors that could occur would be converted into our error representations. I considered that one of the major selling points of error handling in Rust: The compiler would be able to point out which foreign errors have not yet been "acknowledged" in the error handling strategy. It was still possible to then proceed to drop the errors on the floor, but dispatching different handling strategies on foreign & internal errors in the same way was trivial to do. Now with failure everything gets shoved into a single, shared Error-type. Keeping information about what kind of error occured either requires littering the code with verbose .context(...) calls or using runtime reflection () and - since almost every error is implicitly convertable to a failure - using ? now feels like working with a method that has throws Exception in its signature in Java. To make things worse, errors from error_chain can actually not be converted to failures because they aren't Sync. This makes using libraries that have switched to failure somewhat painful from an error_chain based application. This kind of "lets throw the types away!" dynlang bullshit should stay out of my Rust ecosystem
|
# ? Mar 30, 2018 00:33 |
|
|
# ? May 28, 2024 14:27 |
Walh Hara posted:So, I'm an idiot and need help. You've only declared the identifier, not initialized it. Unlike go, rust doesn't assume a default value for an identifier with a type but no initializer. code:
|
|
# ? Mar 30, 2018 00:43 |