jmap_tasks_client/lib.rs
1//! JMAP Tasks extension client methods.
2//!
3//! # Usage
4//!
5//! ```rust,no_run
6//! # use jmap_tasks_client::JmapTasksExt;
7//! # async fn example(client: jmap_base_client::JmapClient) -> Result<(), jmap_base_client::ClientError> {
8//! let session = client.fetch_session().await?;
9//! let sc = client.with_tasks_session(session);
10//! let task_lists = sc.task_list_get(None, None).await?;
11//! # Ok(())
12//! # }
13//! ```
14
15#![forbid(unsafe_code)]
16
17pub mod methods;
18
19pub use jmap_base_client::ClientError;
20pub use methods::{
21 AddedItem, ChangesResponse, GetResponse, QueryChangesResponse, QueryResponse, SessionClient,
22 SetError, SetResponse, TaskListSetParams,
23};
24
25// ---------------------------------------------------------------------------
26// JmapTasksExt — the extension trait
27// ---------------------------------------------------------------------------
28
29/// Extension trait adding JMAP Tasks methods to [`jmap_base_client::JmapClient`].
30///
31/// Import this trait to use: `use jmap_tasks_client::JmapTasksExt;`
32/// This trait is **sealed**: implementations outside this crate are not
33/// permitted. The crate adds an `impl` only for
34/// [`jmap_base_client::JmapClient`]. Sealing prevents downstream
35/// divergence (e.g. `impl JmapTasksExt for MySimulator`) and keeps
36/// adding methods to the trait a non-breaking change.
37pub trait JmapTasksExt: sealed::Sealed {
38 /// Bind this client to a JMAP session for use with Tasks methods.
39 ///
40 /// The returned [`SessionClient`] captures the session at construction time.
41 /// After re-fetching the session, construct a new `SessionClient` with the
42 /// updated session.
43 ///
44 /// # Deferred session-capability validation
45 ///
46 /// This constructor accepts ANY [`jmap_base_client::Session`],
47 /// including one whose advertised capabilities do not include
48 /// `urn:ietf:params:jmap:tasks` or whose `primaryAccounts` map has
49 /// no entry for the tasks capability. The constructor performs no
50 /// up-front validation and never fails — its return type is the
51 /// infallible [`methods::SessionClient`], not a `Result`.
52 ///
53 /// Capability and primary-account validation is deferred to every
54 /// individual method call on the returned [`SessionClient`]. If
55 /// the session is unsuitable, those per-method calls return
56 /// [`ClientError::InvalidSession`] with a description like
57 /// `"no primary account for urn:ietf:params:jmap:tasks"`.
58 ///
59 /// Callers that want to guard at the binding site can pre-check
60 /// the session before calling this method via
61 /// [`session.primary_account_id("urn:ietf:params:jmap:tasks")`](jmap_base_client::Session::primary_account_id).
62 fn with_tasks_session(&self, session: jmap_base_client::Session) -> methods::SessionClient;
63}
64
65impl JmapTasksExt for jmap_base_client::JmapClient {
66 fn with_tasks_session(&self, session: jmap_base_client::Session) -> methods::SessionClient {
67 methods::SessionClient {
68 client: self.clone(),
69 session,
70 }
71 }
72}
73
74mod sealed {
75 /// Sealing-trait for [`super::JmapTasksExt`] — see the trait's rustdoc.
76 pub trait Sealed {}
77 impl Sealed for ::jmap_base_client::JmapClient {}
78}