r/learnrust • • 2h ago

No `main` function found in crate for library crate

1 Upvotes

I use RustRover IDEA. And the IDEA prompt me an error as No 'main' function found in crate

rust compiler seems treat the library crate as binary crate. And when I add

[lib]
path = "lib.rs"
crate-type = ["cdylib"]

I have try both path = "lib.rs" and path = "src/lib.rs". path = "lib.rs" works but cannot load other module like mod1.rs and module/mod.rs in the same directory as lib.rs. And after I remove the [lib]. No 'main'function found error return.

I try `cargo test' and the error message shows

error[E0583]: file not found for module `mod1`
 --> src/lib.rs:5:1
  |
5 | mod mod1;
  | ^^^^^^^^^^^^^
  |
  = help: to create the module `mod1`, create file "src/lib/mod1.rs" or "src/lib/mod1/mod.rs"
  = note: if there is a `mod mod1` elsewhere in the crate already, import it with `use crate::...` instead

error[E0583]: file not found for module `mod2`
 --> src/lib.rs:6:1
  |
6 | mod mod2;
  | ^^^^^^^^^^^
  |
  = help: to create the module `mod2`, create file "src/lib/mod2.rs" or "src/lib/mod2/mod.rs"
  = note: if there is a `mod mod2` elsewhere in the crate already, import it with `use crate::...` instead

error[E0583]: file not found for module `module`
 --> src/lib.rs:7:1
  |
7 | mod module;
  | ^^^^^^^^^^
  |
  = help: to create the module `module`, create file "src/lib/module.rs" or "src/lib/module/mod.rs"
  = note: if there is a `mod module` elsewhere in the crate already, import it with `use crate::...` instead

error[E0425]: cannot find function `my_func` in the crate root
   --> src/lib.rs:137:16
    |
137 |         crate::my_func(
    |                ^^^^^^^^^^^^^^^^^^^ not found in the crate root
    |
help: consider importing this function
    |
134 +     use crate::lib::my_func;
    |
help: if you import `my_func`, refer to it directly
    |
137 -         crate::my_func(
137 +         my_func(
    |

error: could not compile `<crate-name>` (bin "crate-name>" test) due to 4 previous errors; 5 warnings emitted

r/learnrust • • 1d ago

Need help with a game

0 Upvotes

My friend needs help to compile a java program and port it to rust for his nokia.

If anyone wants to help him, you can contact him on his discord: roccogiu


r/learnrust • • 1d ago

Just made my first ever project in rust, and i love this language

29 Upvotes

uhhhh heres the code built it day 2 of learning rust if anything i did is overcomplicated please just comment or create an issue https://github.com/PoxiTheDev/learning


r/learnrust • • 2d ago

Is this worth using ?

Post image
0 Upvotes

r/learnrust • • 2d ago

Cargo can't ship prebuilt dependencies. How do you live with the build times?

14 Upvotes

I really like Rust. But build times are one of the few things that really bother me. For one project, we needed to switch off our CI for a while, because every run took 20 minutes and nobody had time yet to set up caching and CI runs got stuck. And my own crate has the same problem.

I maintain mq-bridge, an async crate that moves messages between Kafka, NATS, Postgres, MongoDB, S3, HTTP and more. Every connector is a Cargo feature. Cold dev build of an empty program that depends on it, on an M1:

-cratesbuildtarget dir
all features5343 min 40 s4.7 GB
no features9918 s411 MB

Release builds take 10-20 minutes per target on GitHub Actions. Splitting into many crates doesn't fix that either: a similar but bigger project that did exactly that takes half an hour to build locally and two on GitHub Actions.

The root of it: Cargo has no way to ship a compiled dependency. Every project compiles every crate from source, again and again, on every machine and every CI runner.

My workaround: you build mq-bridge with no features, and every connector you didn't compile in comes from a prebuilt library at runtime:

mq-bridge = {version = "1.5", default-features = false, features = ["plugin"]}

mq_bridge::plugin::load_installed_plugin("full")?;

The library is a 30-35 MB download (brew, conda or a release tarball). I added a dynamic loader that checks availability of API calls on runtime during definition. The slow library build happens once per release in my CI instead of in every project.

But it is a detour. Rust has no stable ABI, so it goes through a C interface. I already had a C library for the Node and Nim packages, otherwise I'd probably have done it differently. And the boundary costs something:

  • 30-40 % memory throughput for single calls, under 10 % when using batch calls. With a real broker, network latency hides most of it.

  • The plugin has its own copy of the engine, so in-memory channels stay on the host side.

  • It's one more dynamic library file to deploy.

I'd rather not need any of this. Is there a better way I'm missing? How do you keep build times and CI under control for crates with many heavy dependencies?


r/learnrust • • 2d ago

Discord bot in Rust

4 Upvotes

I finished the 100 exercises to learn rust book and also took a course at school that used it for half a semester but I never thought of a project to put my knowledge into. Now I have this idea to make a simple discord bot for booking time-slots on a shared remote PC. I can either:

  1. Try to write it in rust as a learning experience

  2. Write it in python to finish quick

I’m also possibly sharing the code with my teammates who may not know rust so that, and wanting to finish it fast discourage me from trying rust discord API.

What are your thoughts?


r/learnrust • • 2d ago

I might be crazy; is there a way to wrap TcpStream in RustCrypto ciphers?

4 Upvotes

Context: I'm writing a Minecraft client (someone go reset the counter), and I'm starting to reach the point of needing to handle encryption. I built a nice system around decoding and encoding seamlessly through the `Read` and `Write` traits, so I could just throw my `TcpStream` into them and magically get the decoded packet out the other end (or throw in a packet and -- you get the picture).

Now, I have my AES/CFB8 cipher ready. Now, my only question is if I can keep using my `Read` and `Write` data handlers or if I need to try something else. Can I somehow get a `Read`/`Write` impl out of a `impl BlockModeEncrypt`?


r/learnrust • • 2d ago

Am I the only one ?

Thumbnail reddit.com
0 Upvotes

r/learnrust • • 3d ago

How do you handle atomic file operations in a CLI tool? (temp dir + rename, Linux vs Windows)

3 Upvotes

Hi everyone,

I’m the developer of Runique, a Django-inspired web framework in Rust. It’s still under heavy development, so please be kind. (Also, I’m French, so sorry for any awkward English.)

I’m currently consolidating the codebase and I’d like your advice on atomic operations.

Take the CLI as an example:

runique new scaffolds a whole project makemigrations generates sea-orm migration files from my own ast/dsl file uploads have the same issue

If something fails midway, the user ends up with a half-generated project or incomplete files.

My plan is to write everything into a temporary directory on the same filesystem as the final destination, then rename it into place once everything succeeded.

My questions:

Is this the idiomatic approach in Rust? Or is there a better pattern? I know rename behaves differently on Linux and Windows (e.g. replacing an existing target, files locked by antivirus or other processes). How do you deal with that in practice? Are there crates you’d recommend (tempfile, atomic-write-file, etc.) or should I stick to std::fs? Do I need to care about fsync for this kind of tool, or is that overkill?

Thanks a lot for any advice!


r/learnrust • • 3d ago

Compiling the Linux kernel with gccrs - Arthur Cohen & Pierre-Emmanuel Patry | EuroRust 2026

Thumbnail
youtu.be
2 Upvotes

r/learnrust • • 3d ago

Populating a HashMap during initialisation?

12 Upvotes

Hi all,

so I have a hash map, nothing very interesting, but I would like to initialize it with some default values at startup, and this is giving me fits..

#[derive(Debug)]
pub struct Parameters {
  parameter: HashMap<Param, f64>,
}
impl Default for Parameters {
  fn default() -> Self {
    let mut p : Parameters;
    for i in 1..NUM_PARAMETERS {
      p.parameter.insert(Param::Num(i as u16), 0.0);
    }
    p
  }
}

This is what I am trying to do, but of course p is uninitialized.

I could probably work around it by adding a wrapper, initializing the hash map and then having the outer wrapper default populate it, but that feels very clunky.

Is there a better way to deal with this that doesn't require me to default it then load it with a separate function?


r/learnrust • • 3d ago

Are compiler inserted checks something you generally have to be wary of or not

Thumbnail reddit.com
1 Upvotes

r/learnrust • • 4d ago

what's the realistic scope of a hobby os written in rust, and where do most projects stall?

0 Upvotes

at what point does a hobby os stop being "just a kernel" and start needing userspace? and does anyone actually cross that line, or do most of these projects die right after "hello from my own kernel" prints?
asking because i've been writing rust in my evenings alongside my godot puzzle game, purely as a way to understand what's actually happening under linux. i've got a freestanding binary booting in qemu with vga text output and a VERY basic keyboard handler, and it's genuinely the most fun i've had coding in ages. i studied english lit, not computing, so this whole world of gdt, page tables and interrupts is new to me and the phil-opp blog posts have been brilliant for a self-taught person like me. the thing is, i can see the cliff ahead: to do anything interesting you need a heap allocator, then a filesystem, then some way to run actual programs, and suddenly it's five years of work. so my main question: has anyone here got a rust hobby os past the toy stage, and if so, what kept you motivated through the boring middle bits? second, smaller one: is a framebuffer with simple drawing a sensible next goal after keyboard input, or is that a trap?


r/learnrust • • 5d ago

Windows 11 Smart App Control keeps blocking Cargo build scripts. How do you deal with this?

Post image
8 Upvotes

Hi everyone!

I'm developing a Rust application on Windows 11, and I keep running into an issue with Windows Smart App Control whenever I use cargo build.

Windows shows this warning:

"Part of this app has been blocked. Some features of cargo.exe may not work because we can't confirm who published build-script-build.exe."

Sometimes I can successfully build my application, but after changing my code and rebuilding, Windows blocks it again.

I've tried running cargo clean and rebuilding. Sometimes that works temporarily, but the problem keeps coming back.

Has anyone experienced this issue? Is there a way to make Windows trust locally compiled Rust executables without disabling Smart App Control entirely?

Thank you


r/learnrust • • 5d ago

Shipping Temporal: How the Rust Ecosystem Built Chrome’s Newest Web API - Shane Carr | EuroRust 2026

Thumbnail
youtu.be
1 Upvotes

r/learnrust • • 5d ago

learn embedded rust with correct debugging and TDD workflow

10 Upvotes

I'm a C firmware dev, looking to learn Rust for the Nth time in the last 6 years! This time I'm serious.

I've done firmware development with basic debugging with no testing experience in the past.

Is there a walkthough tutorial/project that covers this (without actually getting into real opensource contributions)?

Thank you


r/learnrust • • 6d ago

[Project] Floord – My first Rust project, looking for feedback and contributors

0 Upvotes

Hi! I've spent the last few weeks working on a Rust project that organizes files based on their extensions.

It's pretty simple. In fact, I've been learning Rust throughout the process, going from basic syntax to writing tests and benchmarks.

I've barely used AI, mostly just for syntax questions and some data types I wasn't even familiar with. Most of the project has been about learning, experimenting and refactoring things over and over again.

I just wanted to share it here in case anyone wants to help me improve it. I'm honestly running out of ideas for what else to add, so I'd really appreciate any suggestions, feedback or contributions!

And don't be shy about contributing! I'd love to have other people, especially Rust beginners like myself, working on this project.

What is it?

Floord (random name, why not?) is a daemon that monitors a directory (Downloads by default) and moves incoming files to their corresponding directories based on their extensions.

For example:

  • Downloads/document.pdf → Documents/document.pdf

  • Downloads/image.png → Pictures/image.png

  • If no matching directory is found, the file goes to Downloads/Unknown/.

It currently works as a systemd service, and I'm also working on a Windows adaptation (idk how to do it so I'm not really working on it hehehe).

GitHub: https://github.com/polete-bermejo/floord

If you have any doubt about the project you can ask me and I will reply when I can.

Thanks for checking it out! Any feedback is welcome!

P.S. I'm a Spanish developer, so feel free to talk to me in Spanish if you prefer. English is perfectly fine too!


r/learnrust • • 6d ago

Move your problems to compile-time and get new capabilities out of it - Oli Scherer | EuroRust 2026

Thumbnail
youtu.be
3 Upvotes

r/learnrust • • 7d ago

RustCurious 12: Lifetimes

Thumbnail
youtube.com
5 Upvotes

r/learnrust • • 8d ago

Biting the bullet and learning rust

55 Upvotes

I'm finally going to learn rust. My entire professional career I've used Go and some Python scripting. Even my personal projects are written in Go. I decided the best way for me to learn Rust is by translating one of my older projects from Go to Rust. Turns out it's not that simple. There are quirks in Rust that I don't understand (like lifetimes and memory management) and some quirks of Go that Rust is very opinionated about like enums.

I tried converting my chess engine in Go to Rust and ran into quite a bit of challenges that led me conclude that I need to pick up something less complex and learn the language on its own terms. So any advice on that front would be very helpful. I have already downloaded the The Rust Programing Language Book and watched a couple of videos on YT. But I'm a practical learner. I need to build something to really learn this language.