9 个版本
0.1.8 | 2023 年 12 月 27 日 |
---|---|
0.1.7 | 2023 年 12 月 27 日 |
0.1.2 | 2023 年 11 月 14 日 |
#4 in #sport
每月 76 次下载
用于 fit2gpx
220KB
6.5K SLoC
fit-rust
fit-rust
是一个专为读取、写入和合并 Garmin 弹性和互操作性数据传输 (FIT) 协议文件而设计的 Rust 库。它提供了一个高效且类型安全的处理 FIT 文件的方法,适用于体育和健康数据分析与操作。
功能
- 读取 FIT 文件,将其解析为 Rust 友好的结构。
- 将数据写入 FIT 文件。
- 合并多个 FIT 文件中的数据。
安装
将 fit-rust
添加到您的 Cargo 项目中,通过在您的 Cargo.toml
中包含它
[dependencies]
fit-rust = "0.1"
用法
以下是使用 fit-rust 库的一些基本示例。
读取 FIT 文件
use fit_rust::protocol::FitMessage;
use fit_rust::Fit;
use std::fs;
fn main() {
let file = fs::read("tests/test.fit").unwrap();
let fit: Fit = Fit::read(file).unwrap();
for data in &fit.data {
match data {
FitMessage::Definition(msg) => {
println!("Definition: {:?}", msg.data);
}
FitMessage::Data(msg) => {
println!("Data: {:?}", msg.data);
}
}
}
}
写入 FIT 文件
use fit_rust::Fit;
use std::fs;
fn main() {
let file = fs::read("tests/test.fit").unwrap();
let fit: Fit = Fit::read(file).unwrap();
fit.write("tests/write-test.fit").unwrap();
}
合并 FIT 文件
use fit_rust::Fit;
fn main() {
Fit::merge(
vec![
"tests/ride-0-2023-09-29-12-49-21.fit",
"tests/ride-0-2023-09-29-09-41-54.fit",
],
"tests/merge.fit",
)
.unwrap();
}
贡献
欢迎为 fit-rust 贡献。请随时提交 Pull Requests 或创建 Issues 来讨论新功能或报告错误。
许可
fit-rust 在 MIT 许可下发布。
MIT License
Copyright (c) 2020 intent
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
致谢
依赖项
~2MB
~42K SLoC