Last active
July 25, 2020 07:35
-
-
Save kennykerr/8f4f48fbdaca9552dbfd1a0da6e4b534 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
winrt::declare!( | |
// A WinRT struct defined here | |
pub struct StructType { x: i32, y: i32 }; | |
// A WinRT interface defined here (uuid is inferred) | |
// Implemented by the class itself. | |
pub interface IClassType { | |
fn method(&self) -> Result<i32>; | |
} | |
// In languages like C# and C++, these methods are projected as constructors. | |
// Internally, they are implemented by the class factory. | |
pub interface IClassTypeConstructors { | |
fn create_instance() -> Result<ClassType>; | |
fn create_with_int(value: i32) -> Result<ClassType>; | |
} | |
// In languages like C# and C++, these methods are projected as static methods. | |
// Internally, they are implemented by the class factory. | |
pub interface IClassTypeStatics { | |
fn some_static() -> Result<()>; | |
} | |
// A WinRT class defined here (implements both WinRT and COM interfaces) | |
[constructors(IClassTypeConstructors)] | |
[statics(IClassTypeStatics)] | |
pub class ClassyType { | |
fields: file_types | |
} | |
impl IClassType for ClassyType { | |
fn method(&self) -> Result<i32> { | |
Ok(123) | |
} | |
} | |
impl windows::foundation::IStringable for ClassyType { | |
fn to_string(&self) -> Result<winrt::HString> { | |
Ok("hello".into()) | |
} | |
} | |
impl IClassTypeConstructors for ClassType { | |
fn create_instance() -> Result<ClassType> {...} | |
fn create_with_int(value: i32) -> Result<ClassType> {...} | |
} | |
impl IClassTypeStatics for ClassType { | |
fn some_static() -> Result<()> {...} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment