How to create my own crate?


#1

Can anyone guide me step by step on how to create my very own crate and publish on crates.io?

Thank you !!!


#2

Have you read the official Cargo documentation?
https://doc.rust-lang.org/cargo/index.html


#3

Oh yes…I did…but couldn’t understand how to build a library …


#4
cargo new project_name;
cd project_name;
# edit src/lib.rs
cargo doc --open # review what you've done
cargo publish # makes crates.io/crates/project_name

src/lib.rs is your library, and everything that is pub in that file is your library’s interface.


#5

@kornel
@cuviper
This may be a bit off topic so respectfully I do not want to steer away from @staymetal post. However, is there any public review or pruning process we can put our library through before we publish it (small feedback from the dev team or more experienced Rustaceans out there)? To my knowledge anyone can publish anything and I would like to make sure my library meets a certain level of expectation and standard before I publish something.

Thanks
~S

FYI - It will be quite some time before I publish anything but wanted to ask regardless.


#6

There are guidelines for self-review:

https://rust-lang-nursery.github.io/api-guidelines/

I think the current approach is to have no barriers to publishing, and instead rely on crates.io to help find good crates (currently it’s merely a popularity contest, but other ranking methods have been discussed).


#7

If you want review, I’d recommend publishing a 0.0.1 version on crates.io, then posting it here or on /r/rust.

If you have a github repository with the source, and you’ve documented things, people will be glad to give it a run through and see if they can find anything. It’s not too formal, but it isn’t uncommon to see new crate authors making this kind of post asking for reviews.