Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Last active July 25, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennykerr/8f4f48fbdaca9552dbfd1a0da6e4b534 to your computer and use it in GitHub Desktop.
Save kennykerr/8f4f48fbdaca9552dbfd1a0da6e4b534 to your computer and use it in GitHub Desktop.
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