Home > Mobile >  What should I put into FindAppointmentsAsync's &self parameter?
What should I put into FindAppointmentsAsync's &self parameter?

Time:12-08

I'm new to rust and am trying to make use of the windows cargo. But I don't understand what I should set the &self parameter in the FindAppointmentsAsync function.

This is Cargo.toml:

[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",
]

This is 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(())
}

If let store = AppointmentStore::new(); the error is no function or associated item named 'new' found

If let store = AppointmentStore();, the error is expected 1 argument, found 0

If let store = AppointmentStore(""); the error is cannot initialize a tuple struct which contains private fields

CodePudding user response:

You cannot create an AppointmentStore directly, as it has private fields and does not expose a constructor function.

Looking at the docs, there are two ways to get an AppointmentStore:

  • By calling clone on an existing one.
  • By calling RequestStoreAsync on an AppointmentManager or AppointmentManagerForUser.

AppointmentManager is a struct with no fields, so you can create one by simply doing:

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

AppointmentManagerForUser also cannot be constructed directly, and is obtained by calling GetForUser on an AppointmentManager.

  • Related