I have a larger schema (available here in 2 files, generated from the mei-basic.rng rng file, converted via trang. Put them in a schemata/ directory in a crate root). The following build script almost works, but when adding deserialization, it falls on its nose:
use std::{env, error::Error, fs, path::Path};
type Res = Result<(), Box<dyn 'static + Error + Sync + Send>>;
pub fn main() -> Res {
println!("cargo::rerun-if-changed=schemata/mei-basic.xsd");
let mut config = xsd_parser::Config::default()
.with_schema(Path::new("schemata/mei-basic.xsd").to_path_buf())
.with_generator_flags(xsd_parser::config::GeneratorFlags::USE_MODULES)
//.with_renderer_flags(xsd_parser::config::RendererFlags::RENDER_DOCS)
.with_typedef_mode(xsd_parser::config::TypedefMode::NewType)
.with_quick_xml_deserialize_config(true);
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir);
xsd_parser::generate_modules(config)?.write_to_files(&out_dir.join("gen"))?;
fs::write(&out_dir.join("mod.rs"), "mod r#gen; pub use r#gen::*;")?;
Ok(())
}
I get the following error for a lot of different structs:
error[E0599]: the associated function or constant `deserialize_bytes` exists for struct `VoltaElementType`, but its trait bounds were not satisfied
--> /home/martin/recreational/mei-synth/target/debug/build/mei-synth-schema-5d025108b8abc7ae/out/gen/mei/mod.rs:1:406887
|
1 | ...Type :: deserialize_bytes (helper , bytes) ?)) } } impl WithDeserializerFromBytes for Volta { } # [derive (Debug)] pub struct VoltaElementType { pub id : Option < super :: xml :: Id > , # [doc = "Captures text to be used to generate a label for the element to which it’s attached, a \"tool tip\" or prefatory text...
| ^^^^^^^^^^^^^^^^^ --------------------------- associated function or constant `deserialize_bytes` not found for this struct because `VoltaElementType` doesn't implement `DeserializeBytesFromStr` or `FromStr`
| |
| associated function or constant cannot be called on `VoltaElementType` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`VoltaElementType: DeserializeBytesFromStr`
which is required by `VoltaElementType: DeserializeBytes`
`VoltaElementType: FromStr`
which is required by `VoltaElementType: DeserializeBytes`
`&VoltaElementType: DeserializeBytesFromStr`
which is required by `&VoltaElementType: DeserializeBytes`
`&VoltaElementType: FromStr`
which is required by `&VoltaElementType: DeserializeBytes`
`&mut VoltaElementType: DeserializeBytesFromStr`
which is required by `&mut VoltaElementType: DeserializeBytes`
`&mut VoltaElementType: FromStr`
which is required by `&mut VoltaElementType: DeserializeBytes`
note: the traits `DeserializeBytesFromStr` and `FromStr` must be implemented
--> /home/martin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/xsd-parser-types-0.2.1/src/quick_xml/deserialize.rs:484:1
|
484 | pub trait DeserializeBytesFromStr: FromStr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: /home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/str/traits.rs:883:1
|
883 | pub const trait FromStr: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `deserialize_bytes`, perhaps you need to implement it:
candidate #1: `DeserializeBytes`
Let's say it's incredibly hard to debug this, as the generated single-line module takes a really long while to format in VS Code.
Some additional observations so far with this XSD:
- there is a name collision between
xml:space and mei:space. Instead of a nice error message, the generator generates two structs with the same name unless USE_MODULES is enabled.
NewType is required. The automatic detection seems to disregard some uses and generates multiple impl MeiModelLabelLikeTrait for <type-def> which are reported as "conflicting implementation" later. Disable quick_xml generation to get this error.
- Using the larger mei-all.rng schema as a base results in a
InterpreterError(NoType) with no error location which is basically undebuggable. I'm not sure the schema is 100% correct yet, but expect a follow up report on this.
I have a larger schema (available here in 2 files, generated from the mei-basic.rng rng file, converted via
trang. Put them in aschemata/directory in a crate root). The following build script almost works, but when adding deserialization, it falls on its nose:I get the following error for a lot of different structs:
Let's say it's incredibly hard to debug this, as the generated single-line module takes a really long while to format in VS Code.
Some additional observations so far with this XSD:
xml:spaceandmei:space. Instead of a nice error message, the generator generates two structs with the same name unlessUSE_MODULESis enabled.NewTypeis required. The automatic detection seems to disregard some uses and generates multipleimpl MeiModelLabelLikeTrait for <type-def>which are reported as "conflicting implementation" later. Disable quick_xml generation to get this error.InterpreterError(NoType)with no error location which is basically undebuggable. I'm not sure the schema is 100% correct yet, but expect a follow up report on this.