Hmmm… I guess I don’t see why not?
Hmmm… I guess I don’t see why not?
Such a gem of a movie
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.
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.
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 😅.
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.
While there certainly is some blame on the programmers (to the extent that it is useful to even assign blame), I would say it is hardly fair to blame programmers for most mistakes.
Bugs are a fact of life - the presence of bugs can hardly be blamed on a specific programmer. Rather, it is a result of the resources assigned to a project and its quality assurance. Yes, at the end of the day it comes down to the lines of code written, but everything and anyone involved in the process up to that point (like designer, project managers, people managers and of course executives at the top) are to blame as well. Especially the decision-makers who deprioritized security or quality assurance are especially to blame, much more so than the programmer who wrote the line.
In other riveting news, water is wet.
They were also plain C functions in my case, but it doesn’t take too much discipline to only call it through the struct. Also, you can put the struct in a different crate which includes the C bindings to ensure that you can’t call the C bindings without the struct.
Just use the Mutex from the parking_lot crate.
The only time I’ve ever needed a Mutex<()> so far with Rust is when I had to interop with a C library which itself was not thread safe (unprotected use of global variables), so I needed to lock the placeholder mutex each time I called one of the C functions.
Actually I think in this case you’re still better off using a Mutex with “data” inside. I’ve done this before. The idea is that you make a unit struct MyCFuncs
or whatever and then you only call the C functions from methods of that unit struct. Then you can only access those methods once you lock the Mutex and get the instance of the unit struct. It feel elegant to me.
At least use TOML if you like ini, there is no ini spec but TOML can look quite similar.
No thanks, I’ll be staying with
datastruct.nextState()
rather thanconst nextState = prevState.nextState()
You can easily do the first option in Rust, you just use the mut
keyword. That’s it, nothing more than that. And you’ll find that you quite rarely have to do that, and when you do it, it’s actually quite a useful signal to be aware of, since mutability sometimes means a bit more surprising data changes.
Think you would need
Movie { title: "Star Wars".to_owned(), .. }
, the..
is mandatory.