socratesTwo

u/socratesTwo


r/rust•

Hi all, I've gotten to the stage in a project where I need to connect Python to my Rust. After some Googling, PyO3, cpython, and cffi seem to be the most mature ways of doing it, but I lack the experience in this area to make a sensible decision about which to use.

PyO3 seems pretty cool, but it requires the nightly toolchain and I'm not so sure I want to introduce a dependency on that to the company. Dev-ops is already trying to reel me in a bit and I'd rather not push it. cpython seems a bit less fleshed out, but at least (AFAICT) it'll build on stable... and I suspect both of these are using cffi under the hood, so one question is are they a good value or would I be better off skipp

1214

r/rust•

Hi all, I've run into a situation where I think a proc_macro is my best option, but there are a ton of crates with incredibly complicated APIs and I really don't know how to guide myself through the forest of docs to something that might help me get the thing done. I'm aware of proc-macro-workstop, but none of those puzzles quite match what I'm trying to do and I don't want to try to force it into the shape of one of those solutions without someone more knowledgeable than me telling me it's the right move.

My basic problem is this: I have some messages whose schemas are defined in .proto files. Those proto files get compiled to Rust by a build.rs file that delegates to the prost crat

52

r/rust•

Let's say that I have a function fn foo() -> Option<Result<u32>> and I want to pattern match against its results, why doesn't the following work?

match foo() {
    Some(Ok(i)) => todo!(),
    Some(Err(e)) => todo!(),
    None => todo!(),
}

the compiler tells me I didn't cover the case Ok(_), but it sure looks to me like I did...

Edit: Ugh. Nevermind, I was just being an idiot, I didn't see an if clause on one pattern in the real code.

03


r/rust•

Hi all, I'm working on a communication middleware, which I'm spreading across multiple crates. One crate is a library that has the general purpose code, and another is an entry point that uses the middleware to do one particular task. Sending messages over a network is involved, so I'm using Protocol Buffers as the message format and thus prost to compile them (and build.rs files to control that).

So the library has the super generic messages that it needs to be able to do its job, and the entry point has its own messages that are unique to its function. The catch is that the entry point messages need to be able to import messages from the library. No problem, prost allows you to

62

r/rust•

Does anyone know why the following doesn't build?

const GREETING: &'static str = "Hello";
const PLACE: &'static str = "World";
const DOESNT_BUILD: &'static str = concat!(GREETING, ", ", PLACE);

I mean, yes, it's because concat only works for literals, but why should that be the case?

1012

r/rust•

Hi all, I've been quested to ensure that at most one instance of my program is running at a time. No problem, this is what lockfiles are for, so surely there's an easy to use lockfile crate that does the thing, great! However, after reading some of these blog posts I've taken to being a little bit rigorous before adding a new dependency. So I read the source for lockfile and found that it has two instances of unsafe, both of which would be trivial to do safely, but not at "zero cost" (I'd probably use an Option which does require an extra flag).

I certainly have my opinions as to whether or not using unsafe wa

542

r/adafruit•

Hi all, I'm hoping that someone here is connected to the powers that be at Adafruit and can get this to the appropriate person/people. This is neither a complaint nor praise, merely an experience report of the sort that I a maker of things would love to receive from my users.

I'm writing about the DIN Rail Generic PCB Holder I just received from you guys. It was an impulse buy, I was stocking up on gizmos for an upcoming burner art project and saw it and thought "hey, yeah, I do stuff with PCBs, and I have tons of DIN rail laying around, and enclosures are probably a good idea, sold!". My order showed up, complete and on time (as usual!), and it came with the signature "you spent a lot o

13

r/VanLife•

Hi all, I'm just starting to plan my Sprinter conversion and am doing a ton of research / planning in advance. I'm starting with electrical and plumbing, since those are the parts that seem like they constrain the design space most and need to have groundwork laid first. The trouble I'm running into is that there doesn't seem to be something like "the digikey/mcmaster-carr of conversion van equipment", a place with high quality products (ruling out amazon), and a selection so vast that they're more concerned with helping you search than promoting some item.

Don't get me wrong, I think there's a lot of value in forming a relationship with a distributor so that you can ask questions and get

369

r/YoureWrongAbout•
  1. It might be good to have a link to YWA in the sidebar.

  2. Is there any particular reason this podcast isn't available in Google Play? I'd love to have a listen, but having to install yet another app doesn't excite me.

22

r/linuxhelp•

I don't know how, but upgrading from 16.04 has broken ALL tiling window managers in one of two ways: the ones I try to build from source fail because the 18.04 toolchain is already too old, and the ones I install via apt fail by sending nothing to the monitors after I've logged in at the desktop manager. It's not just blackness either, my external monitor thinks it has been unplugged and goes hunting through other inputs. If I use Ctrl+Alt+F1 I get back to GDM, which shows me as logged in but locked, although typing my password again just repeats the blackness.

This latter failure mode happens with all combinations of: Wayland, X11 crossed with awesomewm, xmonad, dwm, i3, subtle,

31

r/Skookum•

Forgive the slightly off topic post, but this is definitely the place where the people will know; do any of you know the name of this connector? It'd obviously be a male NEMA 5-20 if it weren't for the center post... but with the center post I can't find anything like it on McMaster...

53

r/rust•

Hi all! I'm trying to get some macros to play nicely together and I'm not sure how to do it. The goal is to compile a proto file into Rust (currently but not necessarily by using prost and prost-build), and to annotate the Rust types with pyo3::prelude::pyclass so that they're available to Python when my library is used. My build.xml looks like:

use prost_build::Config;

fn main() {
    let messages_dir: PathBuf =
        [env::var("CARGO_MANIFEST_DIR").unwrap(), "msg".to_string()].iter().collect();
    let includes = [messages_dir.clone()];

    let mut config = Config::new();
    config.type_attribute(".", "#[cfg_attr(feature = \"python\", pyclass)]
32

r/redditdev•

It's mostly a passing curiosity, so if it's harder to do than "here's roughly the right part of the API and some sample python, go nuts" I probably don't care enough to find out, but I'd love to be able to browse sub-comments that get way more upvotes than their parents, or by a similar token more upvotes than some ancestor comment, or perhaps, more upvotes than the average ancestor comment. Or comments that outscore the original post by the widest margin, possibly normalized by comment depth.

For that matter, does anyone know of a statistical analysis of the effect of comment depth on overall score?

How hard would that be to do? Would it require configuring a database?

31