dex_sdk/rpc_invoke_options.rs
1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Sustainable Use License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
9use crate::{AttributeLock, AttributeMapLoad, ChannelMapLoad};
10
11/// Adds runtime-selected map instances to one RPC invocation.
12///
13/// Dex unions these selections with the RPC definition's fixed locks and loads, then sorts and
14/// deduplicates their physical names. Locks and loads are independent. Read-modify-write handlers
15/// must add the same AttributeMap instance through both builder methods.
16///
17/// # Examples
18///
19/// ```
20/// use dex_sdk::{AttributeMap, RpcInvokeOptions};
21///
22/// let profiles = AttributeMap::<String>::new("profiles");
23/// let options = RpcInvokeOptions::new()
24/// .lock_attribute_map_instance(profiles.lock("partition-007"))
25/// .load_attribute_map_instance(profiles.load("partition-007"));
26/// ```
27#[derive(Clone, Debug, Default)]
28pub struct RpcInvokeOptions {
29 pub(crate) lock_attribute_map_instances: Vec<AttributeLock>,
30 pub(crate) load_attribute_map_instances: Vec<AttributeMapLoad>,
31 pub(crate) load_channel_map_instances: Vec<ChannelMapLoad>,
32}
33
34impl RpcInvokeOptions {
35 /// Creates empty invocation options that preserve the RPC definition's behavior.
36 pub fn new() -> Self {
37 Self::default()
38 }
39
40 /// Adds one AttributeMap instance lock for this invocation.
41 ///
42 /// This does not load the instance into the handler snapshot.
43 #[must_use]
44 pub fn lock_attribute_map_instance(mut self, lock: AttributeLock) -> Self {
45 self.lock_attribute_map_instances.push(lock);
46 self
47 }
48
49 /// Adds one exact AttributeMap instance to the handler snapshot.
50 #[must_use]
51 pub fn load_attribute_map_instance(mut self, load: AttributeMapLoad) -> Self {
52 self.load_attribute_map_instances.push(load);
53 self
54 }
55
56 /// Adds one exact ChannelMap instance's pending messages to the handler snapshot.
57 #[must_use]
58 pub fn load_channel_map_instance(mut self, load: ChannelMapLoad) -> Self {
59 self.load_channel_map_instances.push(load);
60 self
61 }
62}