LCOV - code coverage report
Current view: top level - libs/utils/src - toml_edit_ext.rs (source / functions) Coverage Total Hit
Test: 2aa98e37cd3250b9a68c97ef6050b16fe702ab33.info Lines: 83.3 % 12 10
Test Date: 2024-08-29 11:33:10 Functions: 14.3 % 7 1

            Line data    Source code
       1            0 : #[derive(Debug, thiserror::Error)]
       2              : pub enum Error {
       3              :     #[error("item is not a document")]
       4              :     ItemIsNotADocument,
       5              :     #[error(transparent)]
       6              :     Serde(toml_edit::de::Error),
       7              : }
       8              : 
       9           60 : pub fn deserialize_item<T>(item: &toml_edit::Item) -> Result<T, Error>
      10           60 : where
      11           60 :     T: serde::de::DeserializeOwned,
      12           60 : {
      13           60 :     let document: toml_edit::Document = match item {
      14           36 :         toml_edit::Item::Table(toml) => toml.clone().into(),
      15           24 :         toml_edit::Item::Value(toml_edit::Value::InlineTable(toml)) => {
      16           24 :             toml.clone().into_table().into()
      17              :         }
      18            0 :         _ => return Err(Error::ItemIsNotADocument),
      19              :     };
      20              : 
      21           60 :     toml_edit::de::from_document(document).map_err(Error::Serde)
      22           60 : }
        

Generated by: LCOV version 2.1-beta