|
Gaukler posted:nom is real good. I’m converting a thing from using hand-rolled parsers (because “I’m only going to need to parse a couple things!”) I'm just going off the latest docs.rs docs which are all updated. The functions are significantly better to use than the macros (with one caveat) but they mostly have a 1-to-1 relationship so if somebody recommends one of the macro parsers (except named!()) there's probably a function parser that's the same name and semantics. If you have a specific question just pop it here, not that I'm an expert or anything. The main downside I've found with the function parsers is that you have to write out the type signature which, especially if you're trying to be generic over your error type, can be quite involved. I just gave up for now and monomorphised my errors which is Fine. gonadic io fucked around with this message at 11:46 on Dec 30, 2020 |
# ? Dec 30, 2020 10:36 |
|
|
# ? May 15, 2024 03:06 |
|
Hey all, I'm quite new to Rust, and I'm basically trying to code up the following:Rust code:
1) Is this the idiomatic way to model initialized/uninitialized data in Rust? The connection may be reset in other internal functions, but re-connecting should be invisible to the caller. Also, I think I'm relying on Rust's optimization that makes None a null pointer, so I don't have to worry about cleaning anything up before calling std::mem::replace. Is that accurate? 2) The exact Peer class is this one: https://docs.rs/enet/0.2.3/enet/struct.Peer.html -- it requires a lifetime to use, and I get a clean build if I mark NetworkManager as having the same lifetime as Peer in the struct definition. However I think this will cause me headaches later, since NetworkManager is really capable of out-living any one Peer. What's the best way to denote this kind of relationship?
|
# ? Jan 9, 2021 00:28 |
|
Pie Colony posted:Hey all, I'm quite new to Rust, and I'm basically trying to code up the following: 1) I'd use Option::replace or even just `self.connect = Some(...)`. In general in rust I find myself dropping into std::mem very rarely. 2) Uh I think you're going to have trouble there. The docs say quote:The lifetime of these instances is not really clear from the ENet documentation. Therefore, Peers are always borrowed, and can not really be stored anywhere. code:
If you must store a (reference to a) Peer, you'll certainly need to store the Host in the NetworkManager too if you're not already storing it somewhere further up. I don't really know what kind of behaviour this library provides or you want out of it so I can't give more specific advice.
|
# ? Jan 9, 2021 00:43 |
|
You could model the state transition with two different types so you don’t have to litter Option checks everywhere. A DisconnectedNetworkManager that holds connection options and can connect() to return a ConnectedNetworkManager that has a Peer (not Option<Peer>) field and can send(). This way, your ConnectedNetworkManager lifetime will also line up with your Peer lifetime as well. This might not make sense if you were expecting it to do a bunch of state transitions and you really do need to keep checking that you’re connected, though.
|
# ? Jan 9, 2021 02:08 |
|
Thanks for the replies. I did get it working, but still struggling a bit with the lifetimes of Peers. - Peer (the packet queue writer) is only obtainable from a &mut Host (https://docs.rs/enet/0.2.3/enet/struct.Host.html) - Sending queued packets and receiving response packets is only possible from a &mut Host (https://docs.rs/enet/0.2.3/enet/struct.Host.html#method.service) - Which means, in a single scope (say, a game loop), I can only queue a packet if I receive a packet first code:
Pie Colony fucked around with this message at 19:07 on Jan 9, 2021 |
# ? Jan 9, 2021 19:03 |
|
You can also get a peer from the Host::peers method I mention above, but as before you can't store it only use it.
|
# ? Jan 9, 2021 19:06 |
|
Doesn't Host::peers also require a mutable reference? I was fiddling with that but couldn't get it working. e: if I call peers() after service() it maybe seems to work? Although I'm more confused now about why Pie Colony fucked around with this message at 19:14 on Jan 9, 2021 |
# ? Jan 9, 2021 19:12 |
|
https://foundation.rust-lang.org/posts/2021-02-08-hello-world/ Rust foundation formed
|
# ? Feb 8, 2021 19:55 |
|
Not gonna lie, I got a bit verklempt when I saw that.
|
# ? Feb 8, 2021 22:06 |
|
Hello hello. I'm a ops/systems person. When I reach for a language to solve a problem with, my current languages of choice are bash, Python, and Go (roughly sorted in ascending order of problem complexity/solution durability). I've been interested in Rust for years, but diving in and becoming fluent in a language is a non-trivial time commitment, and I don't feel under-resourced in terms of language support, so it has been rather down my priority list. A recent drive-by of the rust.org site to scope out changes since the last time I paid attention has made me think it might be time to make that commitment. I see that Rust's async features have matured, have their own book now (though it isn't linked from the main docs page), and are discussed in the editions book as a major topic for the new edition. I've gotten really used to asking machines to do more than one thing at once, leaning pretty heavily on Go's baked-in concurrency (and management thereof), Python's concurrent futures module, and once having gone so far as to write my own worker pool implementation on top of Python 2.5's subprocess module (which didn't enjoy at all, but we do what we must when we're handed an out-of-date system and a ludicrous task). So my questions, for people who have used Rust's async stuff are: how mature/settled would you say the support is? How would you say it compares to async tooling you've used in other languages? And if you didn't already know Rust, and async/concurrency was really important to you, would you dive in now, or would you wait for the next edition? mdxi fucked around with this message at 21:43 on Feb 17, 2021 |
# ? Feb 17, 2021 21:37 |
|
async in Rust is sort of a PITA right now because they never standardized on an async runtime and now there are several incompatible ones with subtly different APIs. So for example if you want to use hyper (http server/client library, good but reinvents a bunch of actor stuff internally), then either you use tokio (which I personally threw out in favor of smol, after tokio had months of API breakages in the run up to tokio 1.0) or put together a shim layer that will make hyper think it's running on tokio. Every async-using library ends up dealing with the same problems, and some have different wrappers to support multiple async runtimes, but most don't. To summarize: Yes the base language async keywords are finally figured out, but I wouldn't call it mature at all given how the library ecosystem is now partitioned among mutually incompatible runtimes. At the same time, async support has IMO been way overhyped. For most use cases, direct threads/mutexes usually end up being faster anyway - and the ownership semantics quickly get complicated when defining the async tasks themselves. As such you may be better off just ignoring async while starting with Rust and maybe start looking at it later when you decide you're lacking that extra frustration in your life.
|
# ? Feb 18, 2021 07:50 |
|
I just want to use actix and Postgres for a simple ‘hello world’ example. But it feels like a rabbit hole of complexity. Arctic using tokio? And futures? What asynchronous crate should I be using, in addition to actix?
|
# ? Mar 11, 2021 17:56 |
|
street doc posted:I just want to use actix and Postgres for a simple ‘hello world’ example. But it feels like a rabbit hole of complexity. Arctic using tokio? And futures? What asynchronous crate should I be using, in addition to actix? To quickly answer your question: actix requires tokio, which is built on top of futures. You absolutely need all 3 depending on how low level you go. To longer answer your question: why specifically have you decided to use actix? Do you mean actix-web? Especially for smaller stuff you can get by with just tokio and futures and don't need a big framework which would cut down the size of the rabbit hole.
|
# ? Mar 11, 2021 18:01 |
|
street doc posted:I just want to use actix and Postgres for a simple ‘hello world’ example. But it feels like a rabbit hole of complexity. Arctic using tokio? And futures? What asynchronous crate should I be using, in addition to actix? i made a simple website using actix web and postgres last year. it wasn’t that complicated imho
|
# ? Mar 12, 2021 02:33 |
|
I made one last weekend and it wasn't that hard. It is different from other languages where you have one framework to rule them all. You kind of need to piece together the web server, DB access, etc all separately. But it all is designed to work together and has good defaults. Honestly you can just copy the example actix-web skeleton with the stack you want and go from there.
|
# ? Mar 12, 2021 02:39 |
|
fart simpson posted:i made a simple website using actix web and postgres last year. it wasn’t that complicated imho What dependency did you use for Postgres? Diesel?
|
# ? Mar 12, 2021 17:25 |
|
street doc posted:What dependency did you use for Postgres? Diesel? It also offers compile-time checking against the actual database to ensure correctness and handles types well. These are both opt-in rather than required, but they're certainly nice to have depending on the requirements of the project. Khorne fucked around with this message at 18:28 on Mar 12, 2021 |
# ? Mar 12, 2021 18:24 |
|
Sqlx is so much better than diesel its obscene.
|
# ? Mar 12, 2021 18:27 |
|
I have had success with rusqlite directly (even if it's somewhat bare) but now I'm thinking about switching to the sqlx wrapper.
|
# ? Mar 12, 2021 18:32 |
|
street doc posted:What dependency did you use for Postgres? Diesel? i used something called r2d2_postgres. dont remember much about it tbh
|
# ? Mar 13, 2021 16:14 |
|
looking at it again and it looks like mostly what i did was stored procs in postgres and wrote a macro in rust to help build queries with the postgres tokio wrapper. r2d2 is just a connection pool thingcode:
fart simpson fucked around with this message at 16:29 on Mar 13, 2021 |
# ? Mar 13, 2021 16:20 |
|
You could make the error handling a lot more concise using the ? operator and maybe a From impl or two, and that macro probably doesn't need to be a macro at all, and if you're using tokio postgres stuff you can probably just await it directly.
|
# ? Mar 13, 2021 19:32 |
|
Both loadenv and dotenv are pulling up my system environment variables, but not the .env in the drat folder. Wtf
|
# ? Mar 14, 2021 02:06 |
|
street doc posted:Both loadenv and dotenv are pulling up my system environment variables, but not the .env in the drat folder. Wtf It might be a permissions issue. Check if the user running your application has access to .env file and that the file is in the current working directory. This could happen if you accidentally create the .env file while root.
|
# ? Mar 14, 2021 06:26 |
|
Ralith posted:You could make the error handling a lot more concise using the ? operator and maybe a From impl or two, and that macro probably doesn't need to be a macro at all, and if you're using tokio postgres stuff you can probably just await it directly. yeah probably. although if i ever decide to touch this again ill probably switch to that sqlx thing people were just talking about. i remember there being a reason i made it a macro, like i tried it another way and it didn’t work. don’t remember why now
|
# ? Mar 14, 2021 10:19 |
|
Dumb question about my Jetbrains IDE but this is really bumming me out: Shouldn't the IDE know that glob is going to return enum `std::result::Result<Paths, PatternError>` instead of unknown? If I change the line to: so make an obviously wrong type, the linter complains with the right type, so I feel like this should be possible. I have all the relevant boxes checked in the PyCharm settings, is this due to the Jetbrains plugin or Windows jank?
|
# ? Apr 22, 2021 02:44 |
|
Worksforme on Windows with IDEA 2021.1. Which Pycharm are you on? I'm using the nightly version of the plugin though, and I have it set to Maximum Features. As in new macro engine, new ("experimental") name resolution engine, build script handling enabled, stdlib metadata retrieval enabled, proc macro expansion enabled. Those last three can only be enabled via the Experimental Features windows (Help > Find Action). Make sure you have the new macro engine and new name resolution engine enabled. If that doesn't do it maybe try the actually experimental features (but those do in fact break sometimes). (also none of those three should affect this case) oh yeah and try File > Invalidate Caches > Invalidate and Restart as a last thing. It's been like a year I think but the plugin used to fail to invalidate outdated caches on occasion for me, leading to malfunctions editedit: also if none of this helps, if you can post the full code (or a minimized variant) with the issue I'll try and figure out what's wrong Malloc Voidstar fucked around with this message at 00:34 on Apr 23, 2021 |
# ? Apr 23, 2021 00:13 |
|
Malloc Voidstar posted:Worksforme on Windows with IDEA 2021.1. Which Pycharm are you on? Sorry it took so long to reply. I decided to do some more research since I'm new to Rust and converting a program from Python. With a fresh set of eyes, I sat down and realized I hadn't namespaced the function. I popped in glob::glob() instead of glob() and everything immediately clicked! Although, then it said the `use glob::glob` line was an unused import so I need to go read more about that stuff as well, since I would have thought `use glob::glob` would make it so that the glob() function I was using came from the glob crate. Thanks for your help, I'll need to remember the invalidate and restart cache thing in the future.
|
# ? Apr 25, 2021 21:40 |
|
Hed posted:Sorry it took so long to reply. I decided to do some more research since I'm new to Rust and converting a program from Python. With a fresh set of eyes, I sat down and realized I hadn't namespaced the function. I popped in glob::glob() instead of glob() and everything immediately clicked! Just FYI you don't need `extern crate blah` for most cases anymore. You can just `use` whatever you want from the external crates directly. More info: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html
|
# ? May 2, 2021 23:28 |
|
This feels wrong.
|
# ? May 4, 2021 21:51 |
|
You either have a gas leak or there are some snakes on the loose in your apartment.
|
# ? May 4, 2021 22:08 |
|
smh borrow checker cramping my style
|
# ? May 5, 2021 16:43 |
|
Ott_ posted:
should be pretty quick to change that to code:
|
# ? May 5, 2021 16:53 |
|
gonadic io posted:should be pretty quick to change that to Yeah that's what I did but it turns out that operation wasn't even what I was supposed to be doing. So I guess the compiler saved me in the end?
|
# ? May 5, 2021 17:09 |
|
Just a friendly heads-up that Rust is one of the languages now officially supported in the recently-updated [code=thing] tags. Enjoy! I tweaked the language of a code block on this page to help show it off. Full list of supported languages/language aliases available here.
|
# ? Jul 2, 2021 07:21 |
|
sweet
|
# ? Jul 2, 2021 12:15 |
|
Testing...Rust code:
|
# ? Jul 2, 2021 12:30 |
|
Neat! Good stuff admins.
|
# ? Jul 2, 2021 12:31 |
|
Rust's GCC backend is getting merged, so now it (in theory) supports all targets that GCC supports: https://github.com/rust-lang/compiler-team/issues/442#issuecomment-876358112 This was the main anti-rust argument I still kept hearing so it's going to be very interesting to see what people do with this on more niche and older platforms.
|
# ? Jul 8, 2021 13:29 |
|
|
# ? May 15, 2024 03:06 |
|
gonadic io posted:Rust's GCC backend is getting merged, so now it (in theory) supports all targets that GCC supports: I wonder if GCC will be better about not barfing on noalias pointers.. or does it even have that optimization that llvm has that keeps breaking?
|
# ? Jul 8, 2021 18:14 |