Skip to content

Conversation

@faervan
Copy link
Contributor

@faervan faervan commented Sep 13, 2025

close #50

    #[test]
    fn recursive_nesting() {
        #[derive(TomlExample, Default, Debug, Deserialize, PartialEq)]
        struct Outer {
            #[toml_example(nesting)]
            _middle: Middle,
        }
        #[derive(TomlExample, Default, Debug, Deserialize, PartialEq)]
        struct Middle {
            #[toml_example(nesting)]
            _inner: Inner,
        }
        #[derive(TomlExample, Default, Debug, Deserialize, PartialEq)]
        struct Inner {
            _value: usize,
        }
        let example = Outer::toml_example();
        assert_eq!(toml::from_str::<Outer>(&example).unwrap(), Outer::default());
        assert_eq!(
            example,
            r#"[_middle]
[_middle._inner]
_value = 0

"#
        );
    }

This causes the toml_example_with_prefix method to change, tho this method should usually only be used via the TomlExample derive macro anyway.

To-do

  • add additional test(s)

I don't think updating the documentation is necessary, as one would expect this to work already

@faervan
Copy link
Contributor Author

faervan commented Sep 13, 2025

I also noticed I made a mistake when I implemented support for flatten, it would put the flattened items at the end with the other nested items, even tho flattened items should be treated as non-nested due to the nature of flattening.
Fixed it and added a test here as well.

@faervan faervan marked this pull request as ready for review September 13, 2025 23:28
@yanganto
Copy link
Owner

Thanks, I think it is ready to go.

The code is clean straightforward enough, and this is just a picky nit suggestion.

If you don't mind, may we add some doc string on fn toml_example_with_prefix of traits. Although this function is not really for public usage and called by macro, the document still good and may helpful for developer to keep maintaining.

@yanganto yanganto merged commit 6b7e811 into yanganto:main Sep 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support recursive nesting

2 participants