@@ -4,7 +4,7 @@ use documented::{Documented, DocumentedFields};
44use toml_edit:: { ArrayOfTables , Decor , Item , RawString , Table } ;
55use tracing:: warn;
66
7- use crate :: error:: ConfigError ;
7+ use crate :: error:: { ConfigError , Result } ;
88
99/// Appends documentation lines as TOML comments to the given `Decor`.
1010///
@@ -52,7 +52,7 @@ pub fn append_docs_as_toml_comments(decor: &mut Decor, docs: &str) {
5252///
5353/// # Returns
5454/// Returns `Ok(())` if successful, or a `ConfigError` if a TOML item is unexpectedly `None`.
55- pub fn annotate_toml_table < T > ( table : & mut Table , is_root : bool ) -> Result < ( ) , ConfigError >
55+ pub fn annotate_toml_table < T > ( table : & mut Table , is_root : bool ) -> Result < ( ) >
5656where
5757 T : Documented + DocumentedFields ,
5858{
6666 Ok ( docs) => {
6767 match value_item {
6868 Item :: None => {
69- return Err ( ConfigError :: Custom ( format ! (
70- "Encountered TomlEditItem::None for key '{key_str}' unexpectedly" ,
71- ) ) )
69+ return Err ( ConfigError :: UnexpectedTomlItem ( key_str. into ( ) ) ) ;
7270 }
7371 Item :: Value ( _) => append_docs_as_toml_comments ( key_mut. leaf_decor_mut ( ) , docs) ,
7472 Item :: Table ( sub_table) => {
@@ -105,14 +103,13 @@ where
105103///
106104/// # Returns
107105/// Returns `Ok(())` if annotation succeeds, or a `ConfigError` if annotation fails on the first table.
108- pub fn annotate_toml_array_of_tables < T > ( array : & mut ArrayOfTables ) -> Result < ( ) , ConfigError >
106+ pub fn annotate_toml_array_of_tables < T > ( array : & mut ArrayOfTables ) -> Result < ( ) >
109107where
110108 T : Documented + DocumentedFields ,
111109{
112110 if let Some ( first_table) = array. iter_mut ( ) . next ( ) {
113- annotate_toml_table :: < T > ( first_table, false ) . map_err ( |err| {
114- ConfigError :: Custom ( format ! ( "Failed to annotate first table in array: {err}" ) )
115- } ) ?;
111+ annotate_toml_table :: < T > ( first_table, false )
112+ . map_err ( |err| ConfigError :: AnnotateFirstTable ( err. to_string ( ) ) ) ?;
116113 }
117114 Ok ( ( ) )
118115}
0 commit comments