9个版本
0.2.5 | 2024年2月23日 |
---|---|
0.2.4 | 2024年2月4日 |
0.1.2 | 2024年2月2日 |
在过程宏中排名第271
每月下载量60次
12KB
117 行
serde_nested_with
这是一个小的过程宏,允许您在嵌套模块或函数中使用serde属性。当您想使用定义在不同模块或crate中的自定义(反)序列化程序时,这很有用。
安装
cargo add serde_nested_with
示例
mod example {
use serde::{Deserialize, Serialize};
use serde_test::{assert_tokens, Token};
use serde_nested_with::serde_nested;
use std::collections::HashMap;
use time::serde::{rfc3339, iso8601};
use time::OffsetDateTime;
// Make sure to add the `serde_nested` attribute above the #[derive(...)]! This will allow the
// macro to modify the #[serde(...)] attributes before serde itself processes them.
#[serde_nested]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Foo {
#[serde_nested(sub = "OffsetDateTime", serde(with = "rfc3339"))]
pub bar: Option<Option<OffsetDateTime>>,
// You can add additional attributes to the original field and they will be preserved.
#[serde(rename = "other")]
#[serde_nested(
sub = "OffsetDateTime",
serde(serialize_with = "iso8601::serialize", deserialize_with = "iso8601::deserialize"),
// In this instance the substituted field needs to implement additional traits in order
// to be used as key in a HashMap. We can use the `derive_trait` attribute to add them.
derive_trait = "PartialEq",
derive_trait = "Eq",
derive_trait = "Hash"
)]
pub baz: HashMap<OffsetDateTime, OffsetDateTime>
}
}
发布流程
当将与SemVer兼容的git标签推送到仓库时,将向crates.io发布新版本的软件包。
贡献
不允许直接推送到main
分支,任何更新都需要打开pull request。所有状态检查通过后,PR将可进行审查和合并。
提交消息应遵循常规提交规范。
项目附带了一个可选的预配置的开发容器,其中包含所有必需的工具。有关如何使用它的更多信息,请参阅containers.dev。
要确保您的更改与项目风格一致,您可以使用pre-commit install
安装预提交钩子。这需要在您的系统上安装pre-commit。
许可证
版权所有 (c) 2024 Lorenzo Murarotto [email protected]
特此授予任何获得此软件及其相关文档副本(以下简称“软件”)的人免费使用该软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,并允许向提供软件的人授予此类权利,但须遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。
本软件按“原样”提供,不提供任何形式的保证,无论是明示的、暗示的,还是关于适销性、特定用途适用性或不侵犯他人权利的保证。在任何情况下,作者或版权所有者都不应对任何索赔、损害或其他责任负责,无论这些责任是源于合同、侵权或其他法律行为,还是与软件或其使用或其他方式相关。
依赖项
~0.7–1.2MB
~26K SLoC