Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e5c6053
fix(validation): fix rfl::OneOf broken .and_then().or_else() composition
clockblocker Nov 29, 2026
89c3661
fix(json): reject uint64 > INT64_MAX instead of silently wrapping int…
clockblocker Nov 28, 2026
b9dc1e9
feat(json-schema): emit oneOf for rfl::TaggedUnion in JSON Schema (#375)
clockblocker Nov 29, 2026
07ef2b6
fix(headers): eliminate -Wextra, -Wextra-semi, -Wsign-conversion, and…
clockblocker Nov 27, 2026
4879f7e
fix(parsing): gate <expected> include behind <version> feature test t…
clockblocker Nov 30, 2026
d9ae712
feat(enums): accept std::string_view in rfl::string_to_enum (#565)
clockblocker Nov 27, 2026
b14e27d
perf(headers): trim <functional>, <sstream>, and unused <map> from th…
clockblocker Nov 28, 2026
6b4a388
fix(yaml): guard rfl::yaml::Reader against recursive aliases and out-…
clockblocker Nov 25, 2026
489eba4
fix(yaml): reject negative-to-unsigned wraparound, narrow integer ove…
clockblocker Nov 29, 2026
79b1268
fix(xml): fix get_field_from_array index increment and write() indent…
clockblocker Nov 27, 2026
4e25859
fix(env): use getenv_s and _dupenv_s under _MSC_VER in rfl::env::Reader
clockblocker Nov 30, 2026
c7aa574
fix(yaml): return error on non-scalar mapping keys instead of silentl…
clockblocker Nov 29, 2026
970f78f
fix(parsing): prevent std::terminate() at noexcept validation, map-ke…
clockblocker Nov 29, 2026
f49d6c8
fix(parsing): capture input keys matching ExtraFields member name
clockblocker Nov 29, 2026
d8892d9
docs(licensing): add THIRD_PARTY_NOTICES for vendored dependencies
clockblocker Nov 29, 2026
ff639f3
fix(enums): backport enchantum MSVC 64-bit enum cast suffix fix
clockblocker Nov 30, 2026
04495b8
fix(json-schema): flatten nested anyOf for optional variants and rfl:…
clockblocker Nov 29, 2026
b9081d0
feat(cli): add rfl::cli::usage to generate usage and help text (#692)
clockblocker Nov 29, 2026
fc9f041
feat(json): add first-class rfl::json read and write flag constants
clockblocker Nov 29, 2026
54c89d2
perf(parsing): isolate per-field helpers in NamedTupleParser, destruc…
clockblocker Nov 29, 2026
a2d46af
perf(internal): add apply_to_fields and avoid NamedTuple in HasDefaul…
clockblocker Nov 29, 2026
dc6fcc6
fix(error): preserve structured Error::details() paths in FieldVarian…
clockblocker Nov 29, 2026
76da80d
perf(internal): use O(log N) exponential + binary search in cpp20::nu…
clockblocker Nov 29, 2026
0ac0ee2
perf(parsing): isolate per-field helpers in ViewReader and ViewReader…
clockblocker Nov 29, 2026
9a5ee9b
feat(enums): add rfl::TransformEnumNames processors (#731)
clockblocker Nov 29, 2026
950382b
feat(reflection): add public rfl::type_name<T>() and rfl::type_name_v<T>
clockblocker Nov 29, 2026
8bc0da9
perf(schema): fast-path scalar defaults in NamedTupleParser::to_schema
clockblocker Nov 29, 2026
8bb958f
feat(json-schema): add rfl::IntegerBounds opt-in processor (#683)
clockblocker Nov 29, 2026
5d8a835
fix(schema): cast char to unsigned char for std::isalnum and add miss…
clockblocker Nov 29, 2026
68161ed
feat(reflection): expose public rfl::StringLiteral header and constex…
clockblocker Nov 29, 2026
698a622
feat(json-schema): add rfl::VariantsAsOneOf opt-in processor (#375)
clockblocker Nov 29, 2026
c840569
perf(parsing): add FieldNameLookup cursor-hint and binary-search fiel…
clockblocker Nov 29, 2026
6648678
fix(schema): unwrap Type::Description and Type::Deprecated in Avro an…
clockblocker Nov 29, 2026
d7c8d1c
feat(enums): add rfl::EnumNames<E> per-enum wire-name trait (#106)
clockblocker Nov 29, 2026
abc8516
feat(json): add rfl::json::Raw for passthrough raw JSON values (#368)
clockblocker Nov 29, 2026
b640722
build(cmake): subproject ergonomics, CMake 3.20 support, warning/lint…
clockblocker Nov 30, 2026
9b382c6
build(cmake): isolate bundled yyjson visibility, support external yyj…
clockblocker Nov 30, 2026
9fe09b9
feat(error): add format-agnostic rfl::ErrorKind with inline zero-allo…
clockblocker Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
652 changes: 509 additions & 143 deletions CMakeLists.txt

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ reflect-cpp and sqlgen fill important gaps in C++ development. They reduce boile
- [Extra fields](#extra-fields)
- [Reflective programming](#reflective-programming)
- [Standard Library Integration](#support-for-containers)
- [Installation](#installation)
- [The team behind reflect-cpp](#the-team-behind-reflect-cpp)
- [License](#license)

### More in our [documentation](https://munich-data-engineering.github.io/reflect-cpp):
- [Installation ↗](https://munich-data-engineering.github.io/reflect-cpp/install/#option-2-compilation-using-cmake)
- [Installation ↗](https://munich-data-engineering.github.io/reflect-cpp/install/#option-3-compilation-using-cmake)
- [C++26 reflection ↗](https://munich-data-engineering.github.io/reflect-cpp/cpp26_reflection)
- [Benchmarks ↗](https://munich-data-engineering.github.io/reflect-cpp/benchmarks)
- [How to contribute ↗](https://munich-data-engineering.github.io/reflect-cpp/contributing)
Expand Down Expand Up @@ -373,6 +374,17 @@ struct Config {
// ./app data.csv -o /tmp/out -v --count=10
```

`rfl::cli::usage` generates the help text from the same struct, for instance for `--help`:

```cpp
if (argc > 1 && std::string_view(argv[1]) == "--help") {
std::cout << rfl::cli::usage<Config>(argv[0], true).value();
// Usage: ./app <input-file> -o|--output-dir=<value> -v|--verbose[=<bool>] --count=<value>
//
// Arguments: ...
}
```

Nested structs, `std::optional`, `std::vector`, enums, `rfl::Flatten` and `rfl::Rename` are all supported. Refer to the [documentation](https://munich-data-engineering.github.io/reflect-cpp/cli) for details.

### Error messages
Expand Down Expand Up @@ -671,6 +683,7 @@ In addition, it supports the following custom containers:
- `rfl::Tuple`: An alternative to `std::tuple` that compiles considerably faster.
- `rfl::Validator`: Allows for automatic input validation.
- `rfl::Variant`: An alternative to `std::variant` that compiles considerably faster.
- `rfl::json::Raw`: Holds a raw JSON value for passthrough serialization and deserialization (JSON only; [details](https://munich-data-engineering.github.io/reflect-cpp/supported_formats/json/#raw-json-passthrough-rfljsonraw)).

#### Custom classes

Expand All @@ -687,6 +700,29 @@ The following compilers are supported for C++-20:
The following compilers are supported for C++-26:
- GCC 16.2 or higher

### Using CMake FetchContent

JSON-only (zero external dependencies — `yyjson`, `ctre`, and `enchantum` are bundled):

```cmake
include(FetchContent)
FetchContent_Declare(reflectcpp
GIT_REPOSITORY https://github.com/munich-data-engineering/reflect-cpp.git
GIT_TAG main # replace with a release tag containing CMake 3.20 / subproject support
GIT_SHALLOW TRUE
GIT_SUBMODULES "")
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

To enable additional formats (for example YAML), set the corresponding `REFLECTCPP_*` option **before** `FetchContent_MakeAvailable(reflectcpp)` (non-JSON format libraries are resolved via `find_package` from system packages, vcpkg, or Conan because `REFLECTCPP_USE_VCPKG` defaults to `OFF` when consumed as a subproject):

```cmake
set(REFLECTCPP_YAML ON)
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

### Using vcpkg

https://vcpkg.io/en/package/reflectcpp
Expand Down Expand Up @@ -722,7 +758,7 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

For other installation methods, refer to the [documentation](https://munich-data-engineering.github.io/reflect-cpp/docs-readme).
For other installation methods, refer to the [documentation](https://munich-data-engineering.github.io/reflect-cpp/install).

### Compiling with C++-26 reflection

Expand Down Expand Up @@ -752,3 +788,5 @@ reflect-cpp includes [YYJSON](https://github.com/ibireme/yyjson), the fastest JS
reflect-cpp includes [compile-time-regular-expressions](https://github.com/hanickadot/compile-time-regular-expressions). CTRE is written by Hana Dusíková and released under the Apache-2.0 License with LLVM exceptions.

reflect-cpp includes [enchantum](https://github.com/ZXShady/enchantum/tree/main). enchantum is written by ZXShady and also released under the MIT License.

See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for full third-party license texts, SPDX identifiers, and CMake/feature inclusion conditions.
322 changes: 322 additions & 0 deletions THIRD_PARTY_NOTICES.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
elseif (REFLECTCPP_STRICT_WARNINGS)
# Restore /W3 for benchmark targets after top-level CMakeLists strips /W3 before setting /W4 on reflectcpp.
add_compile_options(/W3)
endif ()

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++20 -O2")
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(reflect-cpp-all-format-benchmarks)
project(reflect-cpp-all-format-benchmarks LANGUAGES CXX)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(reflect-cpp-json-benchmarks)
project(reflect-cpp-json-benchmarks LANGUAGES CXX)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

Expand Down
23 changes: 23 additions & 0 deletions docs/content/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,26 @@ constexpr auto enumerator_array = rfl::get_enumerator_array<Color>();

In case it's more convenient to get the enumerator values as values of the enum's underlying type rather than values of the enum type itself,
there is also `rfl::get_underlying_enumerators<EnumType>()` and `rfl::get_underlying_enumerator_array<EnumType>()`.

## Custom wire names (`rfl::EnumNames` and `rfl::TransformEnumNames`)

To customize serialized enum wire names across JSON, CLI, Generic, XML, YAML, and JSON Schema without duplicating enumerators as `rfl::Literal<...>`, specialize `rfl::EnumNames<E>` and/or pass a `rfl::TransformEnumNames<...>` processor (`rfl::EnumSnakeCaseToKebabCase`, `rfl::EnumSnakeCaseToCamelCase`, `rfl::EnumSnakeCaseToPascalCase`, `rfl::EnumCamelCaseToSnakeCase`, `rfl::EnumToLowerCase`, `rfl::EnumToUpperCase`):

```cpp
enum class OptimizationLevel { no_opt, size_opt, speed_opt, cxx_standard };

template <>
struct rfl::EnumNames<OptimizationLevel> {
static constexpr rfl::EnumNameTransform transform =
rfl::EnumNameTransform::snake_to_kebab;
static constexpr std::array<rfl::EnumOverride<OptimizationLevel>, 1>
overrides = {{
{OptimizationLevel::cxx_standard, "c++20"},
}};
};
```

- `overrides` (either a static contiguous range or a static `overrides()` returning a borrowed contiguous range such as `std::span<const rfl::EnumOverride<E>>`) takes precedence over `transform`, and also supports enumerators outside the default reflected range.
- `transform` can be either a `rfl::EnumNameTransform` constant or a static callable `transform(std::string_view)` returning `std::string` or `std::string_view`.
- If `rfl::EnumNames<E>` only defines `overrides` (without `transform`), non-overridden enumerators still receive any `rfl::TransformEnumNames<...>` processor passed to `read`, `write`, or `to_schema`.
- Use `rfl::get_enum_wire_names<E, Processors...>()` to inspect resolved `(wire_name, enumerator)` pairs.
45 changes: 41 additions & 4 deletions docs/content/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ Simply use [this recipe](https://conan.io/center/recipes/reflect-cpp).

## Option 3: Compilation using cmake

### Using FetchContent

To consume reflect-cpp directly from a CMake project with JSON support only (zero external dependencies — `yyjson`, `ctre`, and `enchantum` are bundled):

```cmake
include(FetchContent)
FetchContent_Declare(reflectcpp
GIT_REPOSITORY https://github.com/munich-data-engineering/reflect-cpp.git
GIT_TAG main # replace with a release tag containing CMake 3.20 / subproject support
GIT_SHALLOW TRUE
GIT_SUBMODULES "")
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

To enable additional serialization formats (for example YAML), set the corresponding `REFLECTCPP_*` option **before** `FetchContent_MakeAvailable(reflectcpp)`:

```cmake
set(REFLECTCPP_YAML ON)
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

When reflect-cpp is consumed as a subproject, `REFLECTCPP_USE_VCPKG` defaults to `OFF`, so each non-JSON format's underlying library (such as `yaml-cpp`) is resolved via `find_package` from your system packages, vcpkg toolchain, or Conan generator.

### Subproject packaging options & `reflectcpp::headers`

When embedding reflect-cpp inside larger projects or shared libraries, additional CMake controls are available:

- **`REFLECTCPP_USE_BUNDLED_YYJSON`** (defaults to `REFLECTCPP_USE_BUNDLED_DEPENDENCIES`) and **`REFLECTCPP_YYJSON_TARGET`** (defaults to `yyjson::yyjson` when `REFLECTCPP_USE_BUNDLED_YYJSON=OFF`): reuse an existing external `yyjson` target without disabling bundled `ctre`/`enchantum`. *(Note: if you mix `REFLECTCPP_USE_BUNDLED_DEPENDENCIES=OFF` with `REFLECTCPP_USE_BUNDLED_YYJSON=ON`, ensure no external `<yyjson.h>` on your include path shadows the bundled header.)*
- **`REFLECTCPP_HIDDEN_VISIBILITY`** (default `OFF`): compiles static `reflectcpp` with hidden symbol visibility (`-fvisibility=hidden` / `-fvisibility-inlines-hidden`). Bundled `yyjson_*` symbols are already hidden by default on static non-Windows builds so consumer shared libraries never re-export them.
- **`reflectcpp::headers`**: an exported `INTERFACE` target propagating core reflection (`ctre`/`enchantum`) and JSON (`yyjson`) headers, compile features, and compile definitions without linking compiled `reflectcpp` objects (useful for header-only reflection or intermediate `OBJECT` libraries; final binaries/DSOs using out-of-line symbols still link `reflectcpp::reflectcpp`, and non-JSON backends are not propagated through `reflectcpp::headers`).

### Building standalone

This will compile reflect-cpp with JSON support only. You can then include reflect-cpp in your project and link to the binary.

```bash
Expand All @@ -44,6 +79,8 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

> **Tip (Windows multi-config installs):** When installing both `Debug` and `Release` configurations into the same prefix with Visual Studio, pass `-DCMAKE_DEBUG_POSTFIX=d` so Debug (`reflectcppd.lib`) and Release (`reflectcpp.lib`) libraries coexist without overwriting each other.

## Option 4: Include source files into your own build

Simply copy the contents of the folders `include` and `src` into your source repository or add it to your include path and also add `src/reflectcpp.cpp` and `src/reflectcpp_json.cpp` and `src/yyjson.c` to your source files for compilation.
Expand Down Expand Up @@ -72,11 +109,9 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

To use reflect-cpp in your project:
To use reflect-cpp in your project as a subdirectory, set any optional format flags **before** `add_subdirectory`:

```cmake
add_subdirectory(reflect-cpp) # Add this project as a subdirectory

set(REFLECTCPP_AVRO ON) # Optional
set(REFLECTCPP_BSON ON) # Optional
set(REFLECTCPP_CBOR ON) # Optional
Expand All @@ -87,7 +122,9 @@ set(REFLECTCPP_UBJSON ON) # Optional
set(REFLECTCPP_XML ON) # Optional
set(REFLECTCPP_YAML ON) # Optional

target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
add_subdirectory(reflect-cpp) # Add this project as a subdirectory

target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp) # Link against the library
```

### Troubleshooting vcpkg
Expand Down
25 changes: 25 additions & 0 deletions docs/content/json_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ This will result in the following JSON schema:

You can insert this into the tools mentioned above and see the generated code.

## Variants and tagged unions

`rfl::TaggedUnion` becomes `oneOf`: every alternative has a different tag, so a value
matches exactly one of them.

`rfl::Variant` and `std::variant` become `anyOf`, because their alternatives can overlap:
`1` is both an `integer` and a `number`, and `{"width": 1, "height": 2}` matches both
`Square` and `Rectangle` from the example in [variants](../variants_and_tagged_unions).
`oneOf` would reject such values, even though reflect-cpp reads them without problems.

If you know that the alternatives of your variants never overlap, you can pass
`rfl::VariantsAsOneOf` to get `oneOf` for `rfl::Variant` and `std::variant` as well:

```cpp
const std::string json_schema =
rfl::json::to_schema<rfl::Variant<int, std::string>, rfl::VariantsAsOneOf>();
```

Warning: `oneOf` rejects values that match more than one alternative, so with this
processor the schema rejects `1` for `rfl::Variant<int, double>`. Structs can overlap
as well, for instance when additional properties are allowed (see `rfl::NoExtraFields`).

`std::optional` and `rfl::Generic` stay `anyOf` either way. `std::optional` is not
a variant, and the alternatives of `rfl::Generic` overlap (`1` is both an `integer` and a `number`).

## Adding descriptions

JSON schemata also often contain descriptions. reflect-cpp supports this as well.
Expand Down
50 changes: 50 additions & 0 deletions docs/content/processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ reflect-cpp currently supports the following processors:
- `rfl::NoFieldNames`
- `rfl::NoOptionals`
- `rfl::UnderlyingEnums`
- `rfl::VariantsAsOneOf`
- `rfl::SnakeCaseToCamelCase`
- `rfl::SnakeCaseToPascalCase`

Expand Down Expand Up @@ -492,6 +493,19 @@ The resulting JSON string looks like this:
{"radius":2.0,"color":1}
```

### `rfl::VariantsAsOneOf`

By default, the JSON schema describes `rfl::Variant` and `std::variant` as `anyOf`.
By passing the processor `rfl::VariantsAsOneOf` to `rfl::json::to_schema`, they
become `oneOf`:

```cpp
rfl::json::to_schema<rfl::Variant<int, std::string>, rfl::VariantsAsOneOf>();
```

It only changes the schema, not reading or writing. Please refer to
the [JSON schema documentation](../json_schema) for details.

### `rfl::SnakeCaseToCamelCase`

Please refer to the example above.
Expand Down Expand Up @@ -549,6 +563,42 @@ The resulting JSON string looks like this:
{"type":"Person","firstName":"Homer","lastName":"Simpson","age":45}
```

## `rfl::TransformEnumNames` (`EnumSnakeCaseToKebabCase`, etc.)

Applies a whole-enum wire-name casing transform to enum fields during reading,
writing, and JSON Schema generation. Resolved wire-name tables are cached once
per `(EnumType, EnumNameTransform)` pair.

Built-in aliases:
- `rfl::EnumSnakeCaseToKebabCase`
- `rfl::EnumSnakeCaseToCamelCase`
- `rfl::EnumSnakeCaseToPascalCase`
- `rfl::EnumCamelCaseToSnakeCase`
- `rfl::EnumToLowerCase`
- `rfl::EnumToUpperCase`

```cpp
enum class CostModel { t_count, two_qubit_gate_count, gate_count };
struct Config { CostModel cost_model; };

const auto json_str = rfl::json::write<rfl::EnumSnakeCaseToKebabCase>(
Config{.cost_model = CostModel::two_qubit_gate_count});
// {"cost_model":"two-qubit-gate-count"}
```

## `rfl::IntegerBounds`

Opt-in schema processor that emits C++ integer width `minimum` and `maximum`
keywords in JSON Schema for signed and unsigned integer types (`int8_t`–`int64_t`,
`uint8_t`–`uint64_t`, etc.), excluding `bool`, character types (`char`, `wchar_t`,
`char8_t`, `char16_t`, `char32_t`), and `rfl::UnderlyingEnums`.

```cpp
struct NetConfig { uint16_t port; };
const auto schema = rfl::json::to_schema<NetConfig, rfl::IntegerBounds>();
// "port": {"type":"integer","minimum":0,"maximum":65535}
```

## Writing your own processors

In principle, writing your own processors is not very difficult. You need to define a struct, which takes has a static method called `process` taking a named tuple as an input and then returning a modified named tuple. The `process` method should accept the type of the original struct as a template parameter.
Expand Down
28 changes: 27 additions & 1 deletion docs/content/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,28 @@ struct ErrorDetail {

// The message, without the "Failed to parse field '...': " prefixes.
std::string message;

// Coarse, format-agnostic category of this failure.
rfl::ErrorKind kind = rfl::ErrorKind::other;

bool operator==(const ErrorDetail&) const = default;
};
```

`rfl::ErrorKind` (`enum class ErrorKind : std::uint8_t`) classifies input and I/O failures across formats without requiring callers to parse error message strings. It is an open enum (new enumerators may be added in minor releases; `switch` statements should include a `default:` branch):

- `rfl::ErrorKind::other` – unclassified error (custom parsers/reflectors, caller bugs, or formats not yet tagged; default for plain-string `rfl::Error`).
- `rfl::ErrorKind::io_error` – input could not be obtained or output could not be emitted (file open/read/write/close or stream I/O failure).
- `rfl::ErrorKind::syntax_error` – malformed input syntax (for example invalid JSON).
- `rfl::ErrorKind::missing_field` – a declared, individually-required slot has no entry (required struct field, tuple element, or tagged-union discriminator).
- `rfl::ErrorKind::unknown_field` – an undeclared or ambiguous key/field was encountered (for example under `rfl::NoExtraFields`).
- `rfl::ErrorKind::invalid_length` – element or value count violated a bound fixed by the C++ type or option arity (for example `std::array<T, N>` size mismatch, tuple overflow, or `inplace_vector` capacity).
- `rfl::ErrorKind::invalid_type` – the node's native wire or structural type was incompatible with the target type (for example a string where an integer was expected, or an array where an object was expected).
- `rfl::ErrorKind::invalid_value` – the wire type was right (or a string-only format token), but domain or lexical conversion failed (for example an out-of-range integer, a negative integer for an unsigned target, an unknown enum or `rfl::Literal` value, an invalid timestamp/Base64/bitset, or an unknown union discriminator).
- `rfl::ErrorKind::constraint_violation` – the value parsed to the target C++ type, but violated a declared check such as `rfl::Validator<...>`.

`Error::kind()` returns the error's `rfl::ErrorKind` directly (for multi-error results, it returns the `kind` of the first entry in `.details()`). Note that `ErrorDetail::operator==` compares `kind` in addition to `path` and `message`.

Field names are spelled as they appear in the input, that is, after processors such as `rfl::SnakeCaseToCamelCase` or `rfl::SnakeCaseToKebabCase` (which `rfl::cli::read` uses) have been applied. This means the paths line up with the JSON schema generated by `rfl::json::to_schema`.

```cpp
Expand All @@ -174,8 +193,10 @@ const auto result = rfl::json::read<Request, rfl::SnakeCaseToCamelCase>(

for (const auto& detail : result.error().details()) {
// First iteration: path = {"files", 1, "inputFile"},
// kind = rfl::ErrorKind::constraint_violation,
// message = "Size validation failed: ..."
// Second iteration: path = {"files", 1, "outputFile"},
// kind = rfl::ErrorKind::missing_field,
// message = "Field named 'outputFile' not found."
}
```
Expand All @@ -184,7 +205,12 @@ An error that does not belong to any particular field, such as a syntax error in

## `rfl::error`

`rfl::error("error message")` is a simple utility function for `rfl::Unexpected<Error>(Error("error message"))`.
`rfl::error("error message")` is a simple utility function for `rfl::Unexpected<Error>(Error("error message"))`. You can also pass an `rfl::ErrorKind` (and optionally a `std::vector<rfl::ErrorDetail::PathSegment>` path):

```cpp
rfl::error("Port out of range", rfl::ErrorKind::invalid_value);
rfl::error("Port out of range", rfl::ErrorKind::invalid_value, {"port"});
```

## `.or_else(...)`, `.transform_error(...)`

Expand Down
Loading
Loading