|
1 | 1 | ## Low-level metadata library for ECMA-335
|
| 2 | + |
| 3 | +The [windows-metadata](https://crates.io/crates/windows-metadata) crate provides a reader and writer |
| 4 | +for the ECMA-335 metadata format used by .NET, WinRT, and more recently the Win32 metadata. |
| 5 | + |
| 6 | +* [Getting started](https://kennykerr.ca/rust-getting-started/) |
| 7 | +* [Samples](https://github.com/microsoft/windows-rs/tree/master/crates/samples) |
| 8 | +* [Releases](https://github.com/microsoft/windows-rs/releases) |
| 9 | + |
| 10 | +Start by adding the following to your Cargo.toml file: |
| 11 | + |
| 12 | +```toml |
| 13 | +[dependencies.windows-metadata] |
| 14 | +version = "0.59" |
| 15 | +``` |
| 16 | + |
| 17 | +Use the Windows metadata support as needed. Here is how you might use the reader to query type information: |
| 18 | + |
| 19 | +```rust,no_run |
| 20 | +use windows_metadata::*; |
| 21 | +
|
| 22 | +let index = reader::Index::read("Windows.winmd").unwrap(); |
| 23 | +
|
| 24 | +let def = index.expect("Windows.Foundation", "Point"); |
| 25 | +assert_eq!(def.namespace(), "Windows.Foundation"); |
| 26 | +assert_eq!(def.name(), "Point"); |
| 27 | +
|
| 28 | +let extends = def.extends().unwrap(); |
| 29 | +assert_eq!(extends.namespace(), "System"); |
| 30 | +assert_eq!(extends.name(), "ValueType"); |
| 31 | +
|
| 32 | +let fields: Vec<_> = def.fields().collect(); |
| 33 | +assert_eq!(fields.len(), 2); |
| 34 | +assert_eq!(fields[0].name(), "X"); |
| 35 | +assert_eq!(fields[1].name(), "Y"); |
| 36 | +assert_eq!(fields[0].ty(), Type::F32); |
| 37 | +assert_eq!(fields[1].ty(), Type::F32); |
| 38 | +``` |
0 commit comments