T
Thinking about it a bit more, I believe it’s incredibly rare to want to create a new binding with an ALL_CAPS name; essentially every time that occurs the user’s intention is likely to refer to a constant but either there’s a typo or the name is not imported. For the latter case it would be good to look up type-matching constants in accessible scopes and to suggest importing one if found. This case of manually moving a const to another module, accidentally changing the meaning of a pattern, is…
T
MASHMARO2718: What I'm wondering is whether preserving behavior this explicitly is actually something people care about in practice. I wonder what you mean by that. I would have thought that preserving the behaviour is the whole point of such a translation. I can't help thinking that trying to do a straightforward almost line by line translation of C++ to Rust is never going to work well if the original code makes use of classes and inheritance etc. Rather one needs to extract the algorithmic…
T
Thanks again, @Anlis! I've worked through your list: address from the environment, interval in the reaper, the reaper joins shutdown, SIGTERM, DefaultBodyLimit, FromRow and query_scalar, CancellationToken, and all SQL now lives in a PgStore DAO. A trait for mocking in tests is next.
T
Yes, but the difference is that matches! never binds anything (user-visibly) so trying to do so is more likely to be a mistake. Of course adding a lint for it would require making matches! a special case known to the compiler.
T
MASHMARO2718: I'm curious what you think about this approach. Do you see any fundamental problems with separating the two stages like this? I think the idea you're going for is that you'll be able to incrementally port small parts of the C++ code to Rust, but I'm not sure this is viable or desirable as it requires refactoring your data structures to be Rust-compatible anyway. At that point you might as well just use FFI.
T
I would advice to take inspiration from other successful C++ to Rust rewrites. One very famous case is Fish shell. You can find a write-up about this rewrite here: Fish 4.0: The Fish Of Theseus.
T
Thanks! The inheritance issue is particularly interesting. I'm actually taking a two-stage approach. Rather than generating idiomatic Rust directly, I first translate C++ to run on a checked memory emulator written in Rust, then gradually remove the emulation wherever possible. By developer decisions, I mean that when the translator can't determine the intended behavior, it stops rather than guessing. Those decisions are recorded and reused to minimize human intervention. The idea is to…
T
Yeah, that's actually why I ended up taking a slightly different approach. Instead of trying to map C++ pointers and ownership directly onto Rust's borrowing rules, I built a checked memory emulator in Rust. The translated code initially operates on this emulated memory rather than relying on Rust's native references to represent C++ pointers. The next step is to gradually remove the emulation wherever possible and recover ordinary Rust code. So I'm effectively separating behavior preservation…
T
The parts I found difficult when I ported Schubfach algorithm[1] were the classes where inheritance was used to reduce the amount of code (simple and double-precision code). It wasn't easy to find an approach in Rust that was convenient and solid. Another one was guaranteeing the safety of the pointer-based code filling the buffer. I made that part in safe code, but I'm having second thoughts. I initially did that for the performances, but I'm not sure it'd actually have a significant impact if…
T
I can't imagine it would work well unless the C++ code is written with Rust's specific memory model and borrowing rules in mind.
T
Has anyone here tried migrating a C++ codebase to Rust? I'm curious about how you dealt with subtle changes in behavior during the migration. I've been experimenting with C++ to safe Rust translation lately, and the more I work on it, the more I feel like syntax is the easy part. Things like undefined behavior, integer overflow, and iteration order are much more interesting (and painful), especially when the translated code compiles and runs but gives slightly different results. One approach…
T
johnbchron: I guess my question is this: is this something that would be accepted into Rust if I were to pursue adding it? I'd be willing to attempt building it if so. What are the criteria under which lints like this are evaluated for acceptance? The easiest way to find out is to open an issue and flag this as a Diagnostics Issue (you'll get prompted for what type of issue), linking back to this thread, while also explaining the pitfall you see with the existing diagnostics and what change…
T
Thanks! HookForge reads its settings from the environment at startup and has no config file yet, so I'll keep SIGHUP in mind for when I add one.
T
You have derived Serde's Deserialize for it. You could simply read your JSON file as a string and then run serde_json::from_str to deserialize it.
T
If you're going to handle SIGTERM you might want to handle SIGHUP which is usually used for things like configuration changes if you plan to use a configuration file. You may not need this yet.
T
Thank you, @Anlis, this is a really useful list! You're right about the body limit: my check only runs after the whole body is read, so I'll move it to Axum's built-in limit layer so oversized requests are rejected before they're parsed. My plan: Quick fixes: server address from the environment, tokio::time::interval in the reaper, include the reaper in graceful shutdown, and handle SIGTERM for Docker. Body limit via Axum's limit layer. FromRow structs and query_scalar instead of tuples, and…
T
I'm new in Rust and I'm working on simple CLI program, so I have a problem. The problem is I create a new object every single time when I run a program but I want to load from JSON. I don't know how to implement it because another part of my code using this object to manipulate with others things in program. This is the part of my main file: fn main() { let mut new_user = Profile::new(); loop { println!("=== MENU ==="); println!("1 - show profile"); println!("2 - add hours"); println!("3 -…
T
New week, new Rust! What are you folks up to?
T
The change to make a readme that strips out images and inserts links to elsewhere or some other placeholder could be done mechanically. Even with a sed script if you took some care about how you formatted the markdown file. That wouldn't work if you want to rewrite and reflow the text to avoid the mention of the images entirely, but it would work if you are okay with something like "please see the readme in the repo to see images"
T
On Linux desktop I better like to just use the official rust up, not the one in the distribution. Lately I see the distribution just as a base on which install apps from flatpak and tools using the classic curl | sh approach taken by almost all projects I am interested in.
T
Thank you very much, you’re absolutely right; there are many Linux distributions whose packages aren’t particularly up to date. Nevertheless, your opinion is very valuable.
T
Thank you very much for sharing your views and your words of encouragement.
T
It’s not the process itself that’s complicated; it’s more that, on macOS or Windows, the process is often very tedious and, above all, you have to check that certain programmes are installed. The idea behind my project is to do all of that simply by running a single programme.
T
I feel a little sorry to bump the thread since it seems mostly over but my code above is incorrect: max_len should include the size of the NULL byte since that has to fit in isize::MAX for the underlying allocation. The above code will overflow if max_len == isize::MAX
T
Is setting up Rust on different OSs that messy?
T
Looks like an obvious answer! My code had a few steps in between that ended up creating new values due to operations being done on them which caused some confusion on my end.
T
Looks like it returns a (shared) reference, inside an Option. docs.rs pub fn get<I: Index>(&self, index: I) -> Option<&Value> - Value in serde_json -... Index into a JSON array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array. | Represents any valid JSON value.
T
Simple question. I have a Value which contains a non-strict json value which can be any nested structure. If I get an object property using my_value.get(index), does it clone or return a reference?
T
It can be an interesting project, since Rust provides too many options how it should be installed. Currently I have a complete mess, like some machine use a night build versions, some production, but old, some can build on Windows without any additional installation, some requires link.exe. So certainly I will watch your efforts until they will shape your project in a powerful tool.