Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement/interface macro docs are outdated #3302

Open
beanbean97 opened this issue Sep 30, 2024 · 4 comments
Open

implement/interface macro docs are outdated #3302

beanbean97 opened this issue Sep 30, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@beanbean97
Copy link

Summary

ver: windows-rs 0.58

use windows::core::*;

#[interface("094d70d6-5202-44b8-abb8-43860da5aca2")]
unsafe trait IValue: IUnknown {
    fn GetValue(&self, value: *mut i32) -> HRESULT;
}

#[implement(IValue)]
struct Value(i32);

impl IValue_Impl for Value {
    unsafe fn GetValue(&self, value: *mut i32) -> HRESULT {
        *value = self.0;
        HRESULT(0)
    }
}

get compile error=>

error[E0277]: the trait bound `Value_Impl: IValue_Impl` is not satisfied
 --> src\test.rs:8:1
  |
8 | #[implement(IValue)]
  | ^^^^^^^^^^^^^^^^^^^^ the trait `IValue_Impl` is not implemented for `Value_Impl`
  |
  = help: the trait `IValue_Impl` is implemented for `arc_stream::Value`
note: required by a bound in `IValue_Vtbl::new`
 --> src\test.rs:4:14
  |
3 | #[interface("094d70d6-5202-44b8-abb8-43860da5aca2")]
  | ---------------------------------------------------- required by a bound in this associated function
4 | unsafe trait IValue: IUnknown {
  |              ^^^^^^ required by this bound in `IValue_Vtbl::new`
  = note: this error originates in the attribute macro `implement` (in Nightly builds, run with -Z macro-backtrace for more info)

Crate manifest

No response

Crate code

No response

@beanbean97 beanbean97 added the bug Something isn't working label Sep 30, 2024
@beanbean97
Copy link
Author

ver:0.57 can compile,seem that some change in v0.58 lead this error

@kennykerr
Copy link
Collaborator

This changed here: #3065

Looks like the doc comments are not being compiled. Will have to look into that.

@kennykerr
Copy link
Collaborator

Here's a complete example that should work:

#![allow(non_snake_case)]

use windows_core::*;

#[interface("094d70d6-5202-44b8-abb8-43860da5aca2")]
unsafe trait IValue: IUnknown {
    fn GetValue(&self, value: *mut i32) -> HRESULT;
}

#[implement(IValue)]
struct Value(i32);

impl IValue_Impl for Value_Impl {
    unsafe fn GetValue(&self, value: *mut i32) -> HRESULT {
        *value = self.0;
        HRESULT(0)
    }
}

fn main() -> Result<()> {
    let object: IValue = Value(123).into();

    let mut value = 0;
    unsafe { object.GetValue(&mut value).ok()? };
    println!("{value}");

    Ok(())
}

@kennykerr kennykerr changed the title implement macro can not work on the demo that doc show? implement/interface macro docs are outdated Oct 1, 2024
@beanbean97
Copy link
Author

thanks,that work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants