bevy/crates/bevy_dynamic_plugin
BD103 6990c0ec24
Mark DynamicPluginLoadError internal error types as source (#11618)
# Objective

- [`thiserror`](https://docs.rs/thiserror/) is used to derive the error
type on `bevy_dynamic_plugin`'s
[`DynamicPluginLoadError`](https://docs.rs/bevy_dynamic_plugin/latest/bevy_dynamic_plugin/enum.DynamicPluginLoadError.html).
- It is an enum where each variant wraps a `libloading` error type.
- `thiserror` supports marking this internal error types as `#[source]`
so it can automatically fill out the
[`Error::source`](https://doc.rust-lang.org/std/error/trait.Error.html#method.source)
method.
- This allows other error handling libraries to get more information
about the error than what Bevy by default provides. It increases
interoperability between libraries.

## Solution

- Mark the internal `libloading::Error` of `DynamicPluginLoadError` with
`#[source]`.

---

## Changelog


- Implemented the
[`Error::source`](https://doc.rust-lang.org/std/error/trait.Error.html#method.source)
method for
[`DynamicPluginLoadError`](https://docs.rs/bevy_dynamic_plugin/latest/bevy_dynamic_plugin/enum.DynamicPluginLoadError.html).

---

Here is the output from `cargo-expand` before and after the change.

```rust
// Before
impl Error for DynamicPluginLoadError {}
```

```rust
// After
impl Error for DynamicPluginLoadError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        use thiserror::__private::AsDynError as _;

        match self {
            DynamicPluginLoadError::Library { 0: source, .. } => {
                Some(source.as_dyn_error())
            }
            DynamicPluginLoadError::Plugin { 0: source, .. } => {
                Some(source.as_dyn_error())
            }
        }
    }
}
```
2024-01-30 23:37:00 +00:00
..
src Mark DynamicPluginLoadError internal error types as source (#11618) 2024-01-30 23:37:00 +00:00
Cargo.toml Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00