制作crate并发布到Crates.io

准备

发布 crate 时, 一旦发布无法修改,无法覆盖, 因此要注意邮箱等一些个人信息

访问crates.io帐号设定页面,生成Token

并在命令行 执行 cargo login your token

此命令将告诉 Cargo 你的 API 令牌, 并将其存储在本地 ~/.cargo/credentials

crates.iocrate的名字, 会采取先到先得的方式分配.


打包 & 发布

对于 Cargo.toml:

rs 复制代码
[package]
name = "dashen"
version = "0.1.1"
authors = ["xxxx <x@xxxxxx.tech>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ferris-says = "0.2"

执行cargo publish:

这是因为缺少一些关键信息:关于该 crate 用途的描述和用户可能在何种条款下使用该 cratelicense

想要修正这个错误, 需要在 Cargo.toml 中引入这些信息.

描述通常是一两句话, 它会出现在 crate 的搜索结果中和 crate 页面里.

对于 license 字段, 需要一个 license 标识符值(license identifier value)

Linux 基金会的 Software Package Data Exchange (SPDX) 列出了可以使用的标识符

例如指定 crate 使用 MIT License,可增加 MIT 标识符

rs 复制代码
[package]
name = "dashen"
version = "0.1.1"
authors = ["xxxx <xxx@xxxxx.tech>"]
edition = "2018"
description = "the first crate by xxxxx"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ferris-says = "0.2"

再次执行 cargo publish:

这是因为没有指定git仓库

新建一个仓库,指定为远程仓库,并提交代码

再次执行 cargo publish:

此时也能在crates.io搜到刚刚发布的crate


英文版文档:

Publishing a Crate to Crates.io

中文版文档:

将 crate 发布到 Crates.io

相关推荐
苏打水com2 分钟前
数据库进阶实战:从性能优化到分布式架构的核心突破
数据库·后端
间彧1 小时前
Spring Cloud Gateway与Kong或Nginx等API网关相比有哪些优劣势?
后端
间彧1 小时前
如何基于Spring Cloud Gateway实现灰度发布的具体配置示例?
后端
间彧1 小时前
在实际项目中如何设计一个高可用的Spring Cloud Gateway集群?
后端
间彧1 小时前
如何为Spring Cloud Gateway配置具体的负载均衡策略?
后端
间彧1 小时前
Spring Cloud Gateway详解与应用实战
后端
EnCi Zheng3 小时前
SpringBoot 配置文件完全指南-从入门到精通
java·spring boot·后端
烙印6013 小时前
Spring容器的心脏:深度解析refresh()方法(上)
java·后端·spring
Lisonseekpan3 小时前
Guava Cache 高性能本地缓存库详解与使用案例
java·spring boot·后端·缓存·guava
4 小时前
JUC专题 - 并发编程带来的安全性挑战之同步锁
后端