我是一个新手,正在尝试使用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
1条答案
按热度按时间uubf1zoe1#
不能直接创建
AppointmentStore
,因为它具有私有字段,并且不公开构造函数。查看文档,有两种方法可以获得
AppointmentStore
:clone
。AppointmentManager
或AppointmentManagerForUser
上调用RequestStoreAsync
。AppointmentManager
是一个没有字段的结构体,因此只需执行以下操作即可创建一个:AppointmentManagerForUser
也不能直接构造,而是通过在AppointmentManager上调用GetForUser
来获得。