Search
Can I specify what subset of errors a function can return?
I have two functions that are similar but can fail with different errors:
rust
#[derive(Debug, thiserror::Error)] enum MyError { #[error("error a")] MyErrorA, #[error("error b")] MyErrorB, #[error("bad value ({0})")] MyErrorCommon(String), } fn functionA() -> Result<String, MyError> { // can fail with MyErrorA MyErrorCommon todo!() } fn functionB() -> Result<String, MyError> { // can fail with MyErrorB MyErrorCommon todo!() }
Is there an elegant () way I can express this?
If I split the error type into two separate types, is there a way to reuse the definition of MyErrorCommon
?
() by "elegant" I mean something that improves the code - I'm sure one could define a few macros and solve that way, but I don't want to go there
edit: grammar (rust grammar)
one-liner to avoid "temporary value dropped while borrowed"?
(I'm just starting off with rust, so please be patient)
Is there an idiomatic way of writing the following as a one-liner, somehow informing rustc that it should keep the PathBuf
around?
rust
// nevermind the fully-qualified names // they are there to clarify the code // (that's what I hope at least) let dir: std::path::PathBuf = std::env::current_dir().unwrap(); let dir: &std::path::Path = dir.as_path(); // this won't do: // let dir = std::env::current_dir().unwrap().as_path();
I do understand why rust complains that "temporary value dropped while borrowed" (I mean, the message says it all), but, since I don't really need the PathBuf
for anything else, I was wondering if there's an idiomatic to tell rust that it should extend its life until the end of the code block.
Does one need special drivers for running 3D printers?
Hi there!
I'm looking into getting myself a good printer and I am wondering if I need to install some platform-specific drivers for them to run. I am running Debian 12 (GNU/Linux) and I am afraid that I must run some proprietary blob to connect to the printer.
Could someone share their experience please? Even if you don't use Linux, your feedback would be very appreciated!
(Also, while you are at it, please share some recommendations for printers, I don't really know where to go (>v<) Have about +-500€ )
Preparing for a new cycle of training, I need help to modify my program.
Hello,
a few weeks ago I started my training journey and I am still training, which is a record for me. I'm finishing my first cycle this week and next week and I am planning the next cycle. However, I have a lot of questions and need some help.
Context
I am a 37 yo male that did a lot of sports when I was in my teens/early 20s, but I became sedentary and my diet was shit. I had my second child in October and from October to end of December, I lost 25lbs by changing my diet which motivated me to start training.
On Youtube, I found Jeff Nippard and Renaissance Periodization which gave me a lot of information on how to change my diet (which is ongoing still, but since the end of December, I lost another 5 lbs without trying) and also a lot of information on how to train. And that is how I started weight lifting.
I have two young kids, so it was important to me that I could train at home with minimal equipment, and that is why I bought the Dumbbells only 3 days training from Renai
Misc questions for a newcomer at fitness
Hello,
I made the leap 2 weeks ago to start resistance training and be in better health overall.
I lost 25 pounds since October and it motivated me to start training as well. So here I am.
I bought the Renaissance Periodization 3 days full body workout with dumbbells only to start my journey. I have young kids, so starting at home is giving me the best chance to stick to a program.
With that said, over the 2 weeks, a few questions popped up and I don't know the terminology well enough to answer them and my google skills weren't good enough, so I am trying my luck here.
- I have been sedentary for a long while, even though I did a lot of sport when I was younger. Mainly competitive volley ball, so my legs are decently strong still, but my upper body, not so much. For many upper body exercises I do, it feels like my strength is really uneven, and different muscles are activated, though I make sure that the targeted muscle for the exercise is activated too. Should I stick to the sa