Uppercase letter in crate name

One my project has leading uppercase latter in crate name

Even it works already with few additional libraries, I want make one more application-wide lib crate for some shared features, for all app members. But found that can't use local lib.rs crate, because project has uppercase later in the name.

What should I do now: rename project to lowercase or just create new separated library crate again?

Thanks for advice

You can just add a src/lib.rs file to your existing project, put your shared code in there and use it in your binary crates, all within the same package. No need to create a new package for this. When importing from the library in your binary crates, you are going to see a warning though, because your library does not adhere to the standard naming rules for crates, namely snake_case or kebab-case. You can override the name of your library crate in your manifest file (Cargo.toml) to fix this:

[lib]
name = "yoda"

Then you can just use yoda::*; to import stuff from it in your src/main.rs or other binaries you want to add.

Useful links if you want to explore how Cargo targets work in more details:

https://doc.rust-lang.org/cargo/reference/cargo-targets.html#configuring-a-target

https://doc.rust-lang.org/cargo/reference/cargo-targets.html

https://doc.rust-lang.org/cargo/guide/project-layout.html

1 Like

So I can just define the name for [lib] separately from main project name, that's cool
because, it's my first crate and was worried the letters case does not follow standards to use it as the library also.

Thanks much for solution and related links!

1 Like