Publishing to crates.io
# Complete Cargo.toml for publishing
[package]
name = "my-awesome-crate"
version = "1.0.0"
edition = "2021"
authors = ["Your Name <email@example.com>"]
description = "A brief description of what this crate does"
license = "MIT OR Apache-2.0" # Standard Rust dual license
readme = "README.md"
homepage = "https://github.com/you/my-awesome-crate"
repository = "https://github.com/you/my-awesome-crate"
documentation = "https://docs.rs/my-awesome-crate"
keywords = ["parser", "json", "serialization"] # max 5
categories = ["encoding", "parsing"] # crates.io categoriesDocumentation Best Practices
//! # My Awesome Crate
//!
//! This crate provides tools for awesome things.
//!
//! ## Quick Start
//! ```
//! use my_awesome_crate::Parser;
//! let p = Parser::new();
//! ```
/// Parses a string into a structured format.
///
/// # Arguments
/// * `input` - The string to parse
///
/// # Returns
/// Returns `Ok(ParsedData)` on success, `Err(ParseError)` on failure.
///
/// # Examples
/// ```
/// use my_awesome_crate::parse;
/// let result = parse("hello world").unwrap();
/// assert_eq!(result.word_count(), 2);
/// ```
///
/// # Panics
/// Panics if `input` is empty.
///
/// # Errors
/// Returns `ParseError::InvalidSyntax` if input contains invalid characters.
pub fn parse(input: &str) -> Result {
todo!()
} Workspaces
# Root Cargo.toml for a workspace
[workspace]
members = [
"core",
"cli",
"web-api",
"shared",
]
resolver = "2"
# All crates share a single Cargo.lock
# cargo build builds all members
# cargo test --workspace tests all🎯 Practice
- Create a small utility crate with proper documentation comments including examples
- Run cargo doc --open and verify examples render correctly
- Create a workspace with two crates: a library and a CLI that uses it
🎉 Key Takeaways
- Cargo.toml needs name, version, edition, license, description to publish
- Doc comments (///) with examples are tested by cargo test automatically
- Workspaces share a single lock file and build target directory
- cargo publish --dry-run to check before publishing for real