Skip to main content

ferroui_markup_xaml_winui/
lib.rs

1//! WinUI XAML compatibility of FerroUI: an opt-in importer that migrates WinUI XAML to FerroUI's
2//! XAML, the loading entry points that run it before the run-time loader, and the x:Bind
3//! property-path adapter that the migrated documents use (docs/porting/winui-controls.md and
4//! the plan of #286, W9).
5//!
6//! Nothing here changes the default loader or the ordinary bindings: an application opts in by
7//! calling [`migrate_winui_xaml`] (to feed a build-time compiler) or [`load_winui`],
8//! [`parse_winui`] and [`parse_winui_as`] (run time), and by calling [`register_types`] so that
9//! markup can name the x:Bind types (namespace `FerroUI.Markup.Xaml.WinUI`, reached through the
10//! `using:` prefix the importer writes).
11
12// Generated code names the crate by its name, also in the tests of the crate itself.
13extern crate self as ferroui_markup_xaml_winui;
14
15mod bindings;
16mod importer;
17mod load;
18mod register_types;
19mod rust_paths;
20
21pub use bindings::{
22    WinUIBindExtension, WinUIBinding, WinUIBindingDiagnostic, WinUIBindingErrors, WinUIBindingScope, WinUIBindings,
23};
24pub use importer::{
25    migrate_winui_xaml, WinUIThemeResourcePolicy, WinUIXBindPolicy, WinUIXamlDiagnostic, WinUIXamlDiagnosticSeverity,
26    WinUIXamlEdit, WinUIXamlMemberMapping, WinUIXamlMigration, WinUIXamlMigrationError, WinUIXamlNamespaceMapping,
27    WinUIXamlOptions, WinUIXamlSourceSpan, WinUIXamlTypeMapping, WINUI_PRESENTATION_NAMESPACE,
28};
29pub use load::{load_winui, parse_winui, parse_winui_as};
30pub use register_types::{register_types, ASSEMBLY};
31
32/// Handles of the crate compare by identity (the reference equality of the managed originals).
33macro_rules! identity_eq {
34    ($($type_:ty),* $(,)?) => {$(
35        impl PartialEq for $type_ {
36            fn eq(&self, other: &Self) -> bool {
37                ::std::ptr::addr_eq(self, other)
38            }
39        }
40    )*};
41}
42pub(crate) use identity_eq;
43
44/// The error of a fallible member called through metadata: thrown as the runtime of
45/// `ferroui-markup-xaml` throws (into a scope of `xaml_error_scope::with_xaml_errors`, or as a
46/// panic with its message).
47pub(crate) fn throw<T>(result: Result<T, ferroui_markup_xaml::XamlLoadException>) -> T {
48    match result {
49        Ok(value) => value,
50        Err(error) => ferroui_markup_xaml::xaml_error_scope::throw(error),
51    }
52}
53
54#[cfg(test)]
55mod bindings_tests;
56#[cfg(test)]
57mod compiled_tests;
58#[cfg(test)]
59mod importer_tests;