pub fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>Expand description
Serde 反序列化装饰器,将空字符串映射为 None
§类型参数
D: 反序列化器类型T: 目标类型,必须实现FromStr
§返回
Ok(Some(T)): 非空字符串,成功解析为 TOk(None): 空字符串或 nullErr: 解析失败
§示例
use serde::{Deserialize};
#[derive(Deserialize)]
struct MyStruct {
#[serde(deserialize_with = "axum_bootstrap::util::json::empty_string_as_none")]
value: Option<i32>,
}