Publish Rust SDKs manually
This guide covers publishing Rust SDKs manually. For information on automating Rust SDK publishing, see Publish Rust SDKs automatically.
To share your generated Rust SDK with the community, you can publish it to crates.io. This enables other developers to easily install it using Cargo. Follow the steps below to publish your SDK to crates.io.
Prerequisites
To publish your SDK to crates.io, you need the following:
- A crates.io account (create at crates.io).
- Cargo installed with the Rust toolchain.
- API token from crates.io.
Configure Cargo.toml
Ensure your SDK’s Cargo.toml is properly configured for publication:
Publish your Rust SDK to crates.io
To publish your SDK to crates.io, do the following:
-
Create a crates.io account and get an API token:
- Register at crates.io.
- Go to Account Settings > API Tokens.
- Create a new token with appropriate permissions.
-
Sign in to crates.io using Cargo:
-
Verify your package builds correctly:
-
Test the package build:
-
Publish to crates.io:
-
Verify publication:
Use
cargo install your-sdkonly if your crate also publishes a binary target.
Publish updates
To publish a new version of your SDK:
-
Update the version in
Cargo.toml: -
Update dependencies if needed and test:
-
Publish the new version:
Best practices for publishing Rust SDKs
Use the following best practices when publishing your Rust SDK to crates.io:
- Follow semantic versioning (
MAJOR.MINOR.PATCH). - Include comprehensive documentation with
cargo doc. - Use appropriate keywords and categories for discoverability.
- Test your package thoroughly with
cargo test. - Consider using features for optional functionality.
- Keep your API surface minimal and follow Rust naming conventions.
- Use
#[non_exhaustive]on enums and structs that might grow. - Provide good error messages and use
thiserrorfor error handling.
Advanced configuration
For production SDKs, consider these additional configurations:
Custom feature flags
Documentation settings
This ensures that docs.rs builds your documentation with all features enabled and proper conditional compilation attributes.