Typstyle 开源项目使用教程
typstyleBeautiful and reliable typst code formatter项目地址:https://gitcode.com/gh_mirrors/ty/typstyle
1. 项目的目录结构及介绍
Typstyle 项目的目录结构如下:
typstyle/
├── src/
│ ├── main.rs
│ ├── formatter.rs
│ └── ...
├── tests/
│ ├── test_formatter.rs
│ └── ...
├── examples/
│ ├── example1.typ
│ └── ...
├── .gitignore
├── Cargo.toml
├── README.md
└── ...
目录结构介绍:
- src/: 包含项目的源代码文件,其中
main.rs
是主入口文件,formatter.rs
是格式化逻辑的实现文件。 - tests/: 包含项目的测试代码文件,用于测试格式化功能的正确性。
- examples/: 包含示例文件,展示了如何使用 Typstyle 进行代码格式化。
- .gitignore: Git 忽略文件,指定哪些文件或目录不需要被版本控制。
- Cargo.toml: Rust 项目的配置文件,定义了项目的依赖、版本等信息。
- README.md: 项目的说明文档,通常包含项目的简介、安装方法、使用说明等。
2. 项目的启动文件介绍
Typstyle 的启动文件是 src/main.rs
。这个文件是项目的入口点,负责初始化并启动格式化工具。以下是 main.rs
的简要介绍:
fn main() {
// 初始化配置
let config = load_config();
// 加载待格式化的文件
let input_file = load_input_file();
// 执行格式化
let formatted_code = format_code(input_file, config);
// 输出格式化后的代码
output_formatted_code(formatted_code);
}
主要功能:
- 初始化配置: 从配置文件中加载格式化选项。
- 加载待格式化的文件: 读取用户指定的待格式化文件。
- 执行格式化: 调用格式化逻辑对代码进行格式化。
- 输出格式化后的代码: 将格式化后的代码输出到指定位置。
3. 项目的配置文件介绍
Typstyle 的配置文件是 Cargo.toml
,这是一个标准的 Rust 项目配置文件。以下是 Cargo.toml
的简要介绍:
[package]
name = "typstyle"
version = "0.11.32"
authors = ["Enter-tainer"]
edition = "2021"
[dependencies]
typst = "0.11.1"
[dev-dependencies]
assert_cmd = "1.0.8"
主要配置项:
- [package]: 定义了项目的名称、版本、作者和使用的 Rust 版本。
- [dependencies]: 列出了项目依赖的外部库,例如
typst
。 - [dev-dependencies]: 列出了开发依赖的外部库,例如
assert_cmd
,用于测试。
通过这些配置,Typstyle 能够管理项目的依赖关系,并确保在不同环境下的一致性。
typstyleBeautiful and reliable typst code formatter项目地址:https://gitcode.com/gh_mirrors/ty/typstyle