准备
发布 crate
时, 一旦发布无法修改,无法覆盖, 因此要注意邮箱等一些个人信息
访问crates.io 的 帐号设定页面[1],生成Token
并在命令行 执行 cargo login your token
此命令将告诉 Cargo
你的 API 令牌, 并将其存储在本地 ~/.cargo/credentials

crates.io
上crate
的名字, 会采取先到先得的方式分配.
打包 & 发布
对于 Cargo.toml:
[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 用途的描述和用户可能在何种条款下使用该 crate 的 license
想要修正这个错误, 需要在 Cargo.toml 中引入这些信息.
描述通常是一两句话, 它会出现在 crate 的搜索结果中和 crate 页面里.
对于 license 字段, 需要一个 license 标识符值(license identifier value)
Linux 基金会的 Software Package Data Exchange (SPDX)[2] 列出了可以使用的标识符
例如指定 crate 使用 MIT License,可增加 MIT 标识符
[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[3]搜到刚刚发布的crate

英文版文档:
Publishing a Crate to Crates.io[4]
中文版文档:
将 crate 发布到 Crates.io[5]
参考资料
帐号设定页面: https://crates.io/me
[2]Software Package Data Exchange (SPDX): http://spdx.org/licenses/
[3]crates.io: https://crates.io/search?page=1&per_page=10&q=dashen
[4]Publishing a Crate to Crates.io: https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html
[5]将 crate 发布到 Crates.io: https://kaisery.github.io/trpl-zh-cn/ch14-02-publishing-to-crates-io.html
本文由 mdnice 多平台发布