One more vote for using WASM. Using WASM has the benefit of allowing the user to use almost whatever language they want, as long as it can compile to WASM. So the user doesn’t have to learn some bespoke scripting-specific language.
One more vote for using WASM. Using WASM has the benefit of allowing the user to use almost whatever language they want, as long as it can compile to WASM. So the user doesn’t have to learn some bespoke scripting-specific language.
Definitely let go. Rust has some OOP features, but it’s mostly just the OOP idea of interfaces, which Rust models with traits. You can also do dynamic dispatch, which is another OOP feature, but you should almost never use this in Rust unless you absolutely have to. Then there’s encapsulation which is hugely important in Rust too, but yea outside of that kind of thing, I don’t think OOP patterns are too useful. Honestly, if you ask me, many of these “OOP patterns” are really just solving problems that OOP causes in the first place.
Feel free to ask any other questions.
Thanks for explaining further, it’s a lot clearer now what you want to do. And no, I don’t think this DAO thing is idiomatic for Rust and you probably don’t want to do it like that. I’m not familiar with the pattern though, I’m not too much into OOP myself.
Anyways, I’ve worked a lot with axum and sqlx before so I can tell you what I’d do.
I am writing an axum backend which (like other backends) needs to do stuff in the database. As some endpoints update the database (and sometimes over multiple sql statements) I want to pass around the transaction as this embodies the connection I am using to update the database.
This makes sense. You just want a database connection pool (sqlx provides this) in your axum state so your handlers can get connections to the database.
To separate the axum stuff (parameters, urls and whatnot) from the actual database logic, I’ve first pulled out all the database interactions into separate functions. Because those functions are logically groups (e.g. stuff happening with invoices, others with contacts etc), I thought it was a good idea to create a “dao” struct (and agreed: my OO brain kicked in here which might be debatable). This would group the interactions for each logical domain into a short-lived data access struct.
Again, not sure what this DAO struct actually entails, but what I would do and have done in the past is just do exactly what you said before: “I want to pass around the transaction”. So I would make my functions take the Transaction
struct from sqlx (IIRC it has some type parameters and a life time but you can use a type alias to make it less verbose) and then I would just use that transaction in the function to call SQL. If you have a function that needs access to the database but doesn’t need a transaction, you can just use a plain connection instead of a transaction.
To prevent passing around the transaction/connection, i wanted to pass that along during construction
I’m not sure what you mean with “pass along during construction” but in any case, why do you want to avoid passing the transaction/connection? I feel like that is exactly what you should do. That is what you need to do anyway. Rust favours explicitness and you need to pass the transaction/connection to functions for them to use it, so just pass it.
That’s not what I said. Read about the XY problem and then come back and explain what you actually want to achieve, and give some more information like code examples.
This screams of XY problem. You’ve gotten a new problem from using this method and you’re asking for help for that, but probably there is an underlying better solution that solves your actual use case without running into this problem at all.
most of the cost of [anything] goes to publishers, not the creators
My edit obviously. It does feel like that though. I pay Netflix, not the people making the movie. For games it is at least a bit better - I pay Valve (Steam) and the publisher but at least some of it goes directly to the devs. But it could be better still I suppose. But I’d honestly be okay if we got a Steam-like platform for series and movies where I could buy the ones I want without any subscriptions.
Uh, how? I mean you’d need to make it legal I feel like. But that’s never going to happen and I honestly don’t think that’s fair either. If piracy is legal, how would content creators actually be paid?
I get the sentiment but this is not really an option most of the time if you want to stick with lawful methods. For instance, I cannot watch most movies or TV series these days without a subscription to some service.
Getting fired with cause doesn’t come with severance
Yea this is fucked and needs to be fixed.
Why don’t they just keep working from home and get fired? Instead of having to quit themselves?
So as far as I gather, it’s still just as open source as before but you just can’t sell it on the Confluence marketplace? Seems fair.
Never forget to put glue on pizza, it really brings out a good flavour and makes the cheese all stringy!
It’s a test for the compiler which ensures that these legal yet extremely weird expressions continue to compile as the compiler is updated. So there is a purpose to the madness but it does still look pretty funny.
There’s a crate for it too: anymap2
Not exactly the same thing but this is still pretty funny. This is code that is technically 100% legal Rust but you should definitely never write such code 😅.
I mean… I feel like this could still apply 😅
To save it and save people a click to reddit:
Just about every time I see someone I stop. I kind of got out of the habit in the last couple of years, moved to a big city and all that, my girlfriend wasn’t too stoked on the practice. Then some shit happened to me that changed me and I am back to offering rides habitually. If you would indulge me, it is long story and has almost nothing to do with hitch hiking other than happening on a road.
This past year I have had 3 instances of car trouble. A blow out on a freeway, a bunch of blown fuses and an out of gas situation. All of them were while driving other people’s cars which, for some reason, makes it worse on an emotional level. It makes it worse on a practical level as well, what with the fact that I carry things like a jack and extra fuses in my car, and know enough not to park, facing downhill, on a steep incline with less than a gallon of fuel.
Anyway, each of these times this shit happened I was DISGUSTED with how people would not bother to help me. I spent hours on the side of the freeway waiting, watching roadside assistance vehicles blow past me, for AAA to show. The 4 gas stations I asked for a gas can at told me that they couldn’t loan them out “for my safety” but I could buy a really shitty 1-gallon one with no cap for $15. It was enough, each time, to make you say shit like “this country is going to hell in a handbasket.”
But you know who came to my rescue all three times? Immigrants. Mexican immigrants. None of them spoke a lick of the language. But one of those dudes had a profound affect on me.
He was the guy that stopped to help me with a blow out with his whole family of 6 in tow. I was on the side of the road for close to 4 hours. Big jeep, blown rear tire, had a spare but no jack. I had signs in the windows of the car, big signs that said NEED A JACK and offered money. No dice. Right as I am about to give up and just hitch out there a van pulls over and dude bounds out. He sizes the situation up and calls for his youngest daughter who speaks english. He conveys through her that he has a jack but it is too small for the Jeep so we will need to brace it. He produces a saw from the van and cuts a log out of a downed tree on the side of the road. We rolled it over, put his jack on top, and bam, in business. I start taking the wheel off and, if you can believe it, I broke his tire iron. It was one of those collapsible ones and I wasn’t careful and I snapped the head I needed clean off. Fuck.
No worries, he runs to the van, gives it to his wife and she is gone in a flash, down the road to buy a tire iron. She is back in 15 minutes, we finish the job with a little sweat and cussing (stupid log was starting to give), and I am a very happy man. We are both filthy and sweaty. The wife produces a large water jug for us to wash our hands in. I tried to put a 20 in the man’s hand but he wouldn’t take it so I instead gave it to his wife as quietly as I could. I thanked them up one side and down the other. I asked the little girl where they lived, thinking maybe I could send them a gift for being so awesome. She says they live in Mexico. They are here so mommy and daddy can pick peaches for the next few weeks. After that they are going to pick cherries then go back home. She asks if I have had lunch and when I told her no she gave me a tamale from their cooler, the best fucking tamale I have ever had.
So, to clarify, a family that is undoubtedly poorer than you, me, and just about everyone else on that stretch of road, working on a seasonal basis where time is money, took an hour or two out of their day to help some strange dude on the side of the road when people in tow trucks were just passing me by. Wow…
But we aren’t done yet. I thank them again and walk back to my car and open the foil on the tamale cause I am starving at this point and what do I find inside? My fucking $20 bill! I whirl around and run up to the van and the guy rolls his window down. He sees the $20 in my hand and just shaking his head no like he won’t take it. All I can think to say is “Por Favor, Por Favor, Por Favor” with my hands out. Dude just smiles, shakes his head and, with what looked like great concentration, tried his hardest to speak to me in English:
“Today you… tomorrow me.”
Rolled up his window, drove away, his daughter waving to me in the rear view. I sat in my car eating the best fucking tamale of all time and I just cried. Like a little girl. It has been a rough year and nothing has broke my way. This was so out of left field I just couldn’t deal.
In the 5 months since I have changed a couple of tires, given a few rides to gas stations and, once, went 50 miles out of my way to get a girl to an airport. I won’t accept money. Every time I tell them the same thing when we are through:
“Today you… tomorrow me.”
tl;dr: long rambling story about how the kindness of strangers, particularly folks from south of the border, forced me to be more helpful on the road and in life in general. I am sure it won’t be as meaningful to anyone else but it was seriously the highlight of my 2010.
*edit: To the OP, sorry to jack your thread, this has nothing to do with Hitch Hiking. I sort of thought I could just get this off my chest, enjoy the catharsis and watch the story languish at the bottom of the page. Glad people like hearing the tale and I hope it moves you to be more helpful in your day to day. *
Well in some languages other than English the sun is actually called “Sol”.
Frankly, all of your points sound quite ignorant. Syntax is literally just a matter of getting used to it. Comparing HashMap ergonomics doesn’t make sense, you should rather compare to struct construction. There are many good reasons for different string types and number types. There are good reasons not to bake in async. Rust documentation is in the code for a very good reason and it’s actually really nice to read docs like that (obviously read it on docs.rs, not in the code itself).
I could go on but there are answers to all of your specific qualms if you just bothered to look for yourself.
It’s funny how it used to be expensive. In Danish we have a saying to say someone is poor if “they can’t even afford salt for their egg”, as if an egg is cheaper than salt. Because it actually used to be that way.