windows 我应该在FindAppointmentsAsync的&self参数中输入什么?

6uxekuva  于 2022-12-14  发布在  Windows
关注(0)|答案(1)|浏览(156)

我是一个新手,正在尝试使用windows货物。但是我不明白我应该在FindAppointmentsAsync函数中设置&self参数。
这是货物

[package]
name = "rust-test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies.windows]
version = "0.43.0"
features = [
    "ApplicationModel",
    "ApplicationModel_Appointments",
    "Foundation_Collections",
]

这里是main.rs:

use std::time::Duration;

use windows::{
    core::*, ApplicationModel::Appointments::*, Foundation::{DateTime, TimeSpan},
};

fn main() -> Result<()> {
    let rangestart = DateTime::default();
    let rangelength = TimeSpan::from(Duration::new(60 * 60 * 24 * 30, 0));
    println!("test");

    unsafe {
        let store = AppointmentStore();
        let result = AppointmentStore::FindAppointmentsAsync(&store, rangestart, rangelength);
    }

    Ok(())
}

如果let store = AppointmentStore::new();,则错误为no function or associated item named 'new' found
如果let store = AppointmentStore();,则错误为expected 1 argument, found 0
如果let store = AppointmentStore("");,则错误为cannot initialize a tuple struct which contains private fields

uubf1zoe

uubf1zoe1#

不能直接创建AppointmentStore,因为它具有私有字段,并且不公开构造函数。
查看文档,有两种方法可以获得AppointmentStore

  • 通过在现有服务器上调用clone
  • 通过在AppointmentManagerAppointmentManagerForUser上调用RequestStoreAsync

AppointmentManager是一个没有字段的结构体,因此只需执行以下操作即可创建一个:

let foo = AppointmentManager;
let bar = foo.RequestStoreAsync(/* insert params here */);

AppointmentManagerForUser也不能直接构造,而是通过在AppointmentManager上调用GetForUser来获得。

相关问题