xmpp-rs/xso-proc
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jonas Schäfer 95773505e4 xso-proc: improve error message on type mismatch for extracted fields
The case this affects is a field like:

```
struct Foo {
   #[xml(extract(fields(text(type_ = String)), namespace = .., name = ..))]
   foo: ServiceType,
}
```

Before, we get this:

```
error[E0631]: type mismatch in closure arguments
    --> muchopper/libmuchopper/src/xmpp/sjn_api.rs:188:10
     |
188  | #[derive(AsXml)]
     |          ^^^^^
     |          |
     |          expected due to this
     |          found signature defined here
     |
     = note: expected closure signature `fn(&ServiceType) -> _`
                found closure signature `fn(&'xso_proc_as_xml_iter_lifetime std::string::String) -> _`
note: required by a bound in `std::option::Option::<T>::map`
    --> /home/jssfr/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1102:12
     |
1100 |     pub fn map<U, F>(self, f: F) -> Option<U>
     |            --- required by a bound in this associated function
1101 |     where
1102 |         F: FnOnce(T) -> U,
     |            ^^^^^^^^^^^^^^ required by this bound in `Option::<T>::map`
     = note: this error originates in the derive macro `AsXml` (in Nightly builds, run with -Z macro-backtrace for more info)

```

Afterwards, this:

```
error[E0308]: mismatched types
   --> muchopper/libmuchopper/src/xmpp/sjn_api.rs:207:20
    |
206 |     #[xml(extract(namespace = ECS, name = "service-type", fields(text(type_ = String))))]
    |                                                                               ------ expected due to this
207 |     pub service_type: ServiceType,
    |                       ^^^^^^^^^^^ expected `Option<&String>`, found `Option<&ServiceType>`
    |
    = note: expected enum `std::option::Option<&'xso_proc_as_xml_iter_lifetime std::string::String>`
               found enum `std::option::Option<&ServiceType>`

```

skip-changelog, because this affects a feature which already has an
"Added" line in the changelog.
2025-01-24 18:28:52 +01:00
..
src xso-proc: improve error message on type mismatch for extracted fields 2025-01-24 18:28:52 +01:00
Cargo.toml Unify version string formats 2024-07-25 14:41:04 +00:00
ChangeLog xso-proc: add support for child elements 2024-07-26 22:31:42 +02:00
README.md xso: add README files 2024-07-24 16:27:53 +02:00

xso_proc -- derive macros for XML parsing

Whats this?

This crate provides the derive macros exported by the xso crate. Please see that crate's README and documentation for more information.

What license is it under?

MPL-2.0 or later, see the LICENSE file.