Commit Graph

47 Commits

Author SHA1 Message Date
Lukas Kalbertodt
eb03488973 Fix using env with deserialize_with
Fixes #2

I simply forgot to use the `deserialize_with` attribute for the env
deserialization. The previous code was somewhat weirdly coded in that
we would always deserialize `Option<T>` (as it's a partial type) and
the "env variable not present" info would travel through the
deserializer to the `Option<T> as Deserialize` impl. Now it's more
straight forward.
2022-10-14 16:33:37 +02:00
Lukas Kalbertodt
963e4745a3 Allow unused test utility
This is only unused with `--no-default-features`.
2022-10-11 13:17:19 +02:00
Lukas Kalbertodt
65d0b7ca17 Fix minor docs formatting issue 2022-10-11 12:59:54 +02:00
Lukas Kalbertodt
56f8ff24d5 Improve toml::format regarding space above nested objects 2022-04-07 17:19:38 +02:00
Lukas Kalbertodt
8db8fcafc4 Add two toml::format tests 2022-04-07 14:00:56 +02:00
Lukas Kalbertodt
1c6ecdd4ad Fix doctests using derive
See https://github.com/rust-lang/rust/issues/83583
2022-03-30 17:38:39 +02:00
Lukas Kalbertodt
e801403009 Fix output of toml::format by always handling leaf fields first
Otherwise this:

```
struct Config {
    #[config(nested)]
    foo: ...,
    bar: ...,
}
```

would emit:

```
[foo]

```

Which is incorrect.
2022-03-30 16:15:27 +02:00
Lukas Kalbertodt
a50f78e938 Add deserialize_with attribute that is forwarded to serde 2021-11-03 16:01:57 +01:00
Lukas Kalbertodt
4f4f42e8f3 Disable some code (and fix others) when no features are enabled 2021-07-28 12:38:50 +02:00
Lukas Kalbertodt
8a520927a2 Add crate-level documentation 2021-07-28 12:02:09 +02:00
Lukas Kalbertodt
00dbe4dc0a Fix compilation failure for --no-default-features 2021-07-27 17:16:06 +02:00
Lukas Kalbertodt
cc1a0eba5e Minor documentation improvements 2021-07-27 16:20:24 +02:00
Lukas Kalbertodt
a86ab50588 Add more documentation to Config trait and derive 2021-07-27 16:15:05 +02:00
Lukas Kalbertodt
271a807ab0 Fix emission of TOML strings (in particular, quoting) 2021-07-27 15:10:07 +02:00
Lukas Kalbertodt
0bc105b22d Add yaml::format 2021-07-27 15:05:07 +02:00
Lukas Kalbertodt
74ce2daf05 Add Builder::env to read environment variables 2021-07-27 01:14:00 +02:00
Lukas Kalbertodt
aa5eb06f49 Add Partial::from_env and implement it in derive macro 2021-07-27 01:12:57 +02:00
Lukas Kalbertodt
3ac922ca2f Add deserialization logic for reading values from environment variables 2021-07-27 01:10:12 +02:00
Lukas Kalbertodt
db2aebc270 Parse #[env] attribute and representing it in meta types 2021-07-25 11:36:36 +02:00
Lukas Kalbertodt
3c7376035c Add Config::from_file 2021-07-25 10:56:46 +02:00
Lukas Kalbertodt
ebd8aba2fa Disallow Option<_> type for fields with #[nested] or #[default]
Regarding nested fields: I cannot imagine a situation where that
distinction is useful. Also, specifying an empty nested object looks
stupid in TOML and YAML anyway.

Regarding default fields: If there is a default value, then the field
should not be declared as optional to begin with.
2021-07-25 10:46:06 +02:00
Lukas Kalbertodt
9c5990d803 Add Partial::is_empty and Partial::is_complete 2021-07-25 10:06:46 +02:00
Lukas Kalbertodt
ca5bb2488f Add Builder type as convenient high level loading API 2021-07-25 09:45:59 +02:00
Lukas Kalbertodt
76373278b0 Remove Source trait and Config::from_sources
I'm not sure about a good high level API.
2021-07-24 22:25:40 +02:00
Lukas Kalbertodt
6aece589c4 Add toml::FormatOptions::comments 2021-07-24 19:44:27 +02:00
Lukas Kalbertodt
522494aa5c Fix derive macro for pub(crate) visibility 2021-07-24 18:48:15 +02:00
Lukas Kalbertodt
ceb9799e55 Add toml module with format function for config templates 2021-07-24 18:48:15 +02:00
Lukas Kalbertodt
b663e698ba Implement Display for meta::Integer and meta::Float
Those impls is pretty unambiguous I think.
2021-07-24 18:48:14 +02:00
Lukas Kalbertodt
066e7a0023 Add meta::Field::optional 2021-07-24 18:48:14 +02:00
Lukas Kalbertodt
09cc848b94 Rename #[config(child)] to #[config(nested)] 2021-07-24 18:48:14 +02:00
Lukas Kalbertodt
b71eaa0464 Add Config::META to access the configuration definition at runtime 2021-07-24 18:48:13 +02:00
Lukas Kalbertodt
e3e90430f4 Remove File::toml and File::yaml
The added convenience is minimal over `new`, so I'd rather have a
smaller API and less code with `#[cfg]`.
2021-05-16 16:52:10 +02:00
Lukas Kalbertodt
0d25489a31 Move error code to error.rs 2021-05-16 16:09:49 +02:00
Lukas Kalbertodt
d11f18e5f0 Move File and FileFormat to the crate root
The crate root is not super busy yet, so it's more convenient to have
no public sub modules.
2021-05-16 16:07:36 +02:00
Lukas Kalbertodt
b57382f546 Add some documentation 2021-05-16 15:59:33 +02:00
Lukas Kalbertodt
366fd3d10a Remove example module and doc-example feature
Now that we use derives, not a lot of magic happens anymore. Thus, I
think it's not necessary to show the generated stuff anymore.
2021-05-16 15:30:26 +02:00
Lukas Kalbertodt
32fbfd3a5a Add Source trait and implement it for files (TOML and YAML for now) 2021-05-16 15:27:47 +02:00
Lukas Kalbertodt
8abc07bcda Add handling of nested configuration types via #[config(child)] 2021-05-14 22:13:31 +02:00
Lukas Kalbertodt
0f37618c19 Rewrite everything to be based on derives (WIP) 2021-05-14 16:30:50 +02:00
Lukas Kalbertodt
c798049443 Require single config root object
Otherwise global attributes and attributes for the root object have the
same syntax (`#![...]`). This way, it is way clearer.
2021-04-30 17:51:06 +02:00
Lukas Kalbertodt
651a06b252 Add typename attribute and refactor a bunch
This commit should have been two, I know. I feel bad about it.
2021-04-29 23:18:22 +02:00
Lukas Kalbertodt
5d3ccd7b42 Add support for #[derive] annotations 2021-04-29 20:19:25 +02:00
Lukas Kalbertodt
24dec3b037 Add #![visibility = "..."] attribute to specify visibility 2021-04-29 19:30:19 +02:00
Lukas Kalbertodt
bfab0e8798 Add example module for documentation
It currently doesn't show anything as all items are pub(crate).
2021-04-29 19:00:36 +02:00
Lukas Kalbertodt
1ae45a3e7c Move TryFromError from generated code into main crate
There is not really a point in generating this type for every
invocation. Also reduces the number of things magically generated.
2021-04-29 18:41:17 +02:00
Lukas Kalbertodt
537a8b7725 Add version from other project
This was mostly what I implemented as utility library for another
project. But I figured I can also extract it as it's useful on its
own.
2021-04-29 18:09:26 +02:00
Lukas Kalbertodt
dd52b56548 Initial commit with empty Cargo project 2021-04-29 17:23:54 +02:00