制作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

相关推荐
2601_962063971 小时前
Spring Boot拦截器(Interceptor)详解
java·spring boot·后端
明月_清风1 小时前
GitHub Actions 从入门到实战:一文搞懂 CI/CD 自动化
后端·ci/cd·github
foggyprojects2 小时前
AI 问数也要做行级权限:让 Codex 给销售查询加上权限
后端
千里码aicood3 小时前
flask基于数字人的储粮知识问答原型系统研究与实现
后端·python·flask
考虑考虑3 小时前
arthas使用
java·运维·后端
李昊哲小课4 小时前
Spring Boot 4 旅游主题实战教程 阶段三:数据持久化
spring boot·后端·mybatis·旅游
AI 编程助手GPT4 小时前
Bun 1.4 正式发布:从 Zig 改写为 Rust,内置浏览器、图片处理和并行测试
开发语言·人工智能·后端·ai·chatgpt
IT_陈寒4 小时前
Redis大KEY删除慢到手抖,这几个方法让我少熬一夜
前端·人工智能·后端
步行cgn4 小时前
传统 SSM 与 Spring Boot 开发对比:从配置地狱到约定优于配置
java·spring boot·后端