mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-20 22:50:38 +00:00
Before this PR, `RemoteStorageConfig::from_toml` would support
deserializing an
empty `{}` TOML inline table to a `None`, otherwise try `Some()`.
We can instead let
* in proxy: let clap derive handle the Option
* in PS & SK: assume that if the field is specified, it must be a valid
RemtoeStorageConfig
(This PR started with a much simpler goal of factoring out the
`deserialize_item` function because I need that in another PR).
23 lines
661 B
Rust
23 lines
661 B
Rust
#[derive(Debug, thiserror::Error)]
|
|
pub enum Error {
|
|
#[error("item is not a document")]
|
|
ItemIsNotADocument,
|
|
#[error(transparent)]
|
|
Serde(toml_edit::de::Error),
|
|
}
|
|
|
|
pub fn deserialize_item<T>(item: &toml_edit::Item) -> Result<T, Error>
|
|
where
|
|
T: serde::de::DeserializeOwned,
|
|
{
|
|
let document: toml_edit::Document = match item {
|
|
toml_edit::Item::Table(toml) => toml.clone().into(),
|
|
toml_edit::Item::Value(toml_edit::Value::InlineTable(toml)) => {
|
|
toml.clone().into_table().into()
|
|
}
|
|
_ => return Err(Error::ItemIsNotADocument),
|
|
};
|
|
|
|
toml_edit::de::from_document(document).map_err(Error::Serde)
|
|
}
|