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.
Tbf I do think it qualifies as title gore and at the very least it is missing a comma before “ending”
“Wikipedia concludes that Israel is committing genocide, thus ending an editorial debate”
Yea it’s cool. Although, regarding sublinks, it really looks like the project has stalled.
It doesn’t really help for me, but the beauty of the fediverse is that it doesn’t have to. You can like PieFed, I can prefer Lemmy and we can both still talk :)
On the other hand, it has some weirdly opinionated features:
It creates circles of like-minded people where it is really easy to reject “other” thoughts and accept “our” ideas without much questioning.
I know it sounds counter-intuitive, but there is an argument to be made that we should actually go back to smaller, more secluded forums on the internet that are less connected with outside views.
Hmm okay. I do think we have something similar here where there might be meetings that we call “citizen meetings” where anyone is invited to come and hear about a current political topic. It’s mostly informative and people can ask questions and stuff, not related to campaigning or elections mostly I would say. So yea I don’t think that is too weird honestly.
That just makes me think, how can those people not voting just sit idly by and watch? I don’t understand that either.
I’m not sure about the format but I know that towns in Denmark also occasionally calls for meetings. This doesn’t sound that weird to me
Well the map includes Canada, US, UK and India, and some african territories that I imagine may have been UK colonies at one point (I could be wrong), hence english-speaking world.
I think those are particular examples but if you look at most of the EU, I think there are more political choices than just 2. Here in Denmark there’s sometimes a discussion that there are too many political parties. We currently have like 12?
The weirdest thing, the thing that I have the hardest time understanding, is how many people vote for Trump. There was just a survey here in Denmark asking how many would vote for Trump. It was 8%. That number I still find a bit high but I can understand it a little bit. 8% of people voting for something very harmful seems almost inevitable I guess. Some people just aren’t educated or informed enough.
But the fact that close to 50% of americans choose to vote for Trump, and that in some states, it is even more than 50% - that I don’t think I will ever understand. That is madness.
No, not really. Only some parts of the english-speaking world use FPTP and it’s not that common to have only 2 choices unless you have that system.
Isn’t that quite normal even in other countries? I believe we do it quite commonly in Denmark.
Townhalls are weird.
Town halls? As in the building or does this mean something else? Aren’t town halls quite common and normal elsewhere?
Flags everywhere is weird.
We kinda do this in Denmark too tbh. I personally don’t find it that weird due to that.
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.