Skip to content

Commit 277bb6c

Browse files
aymenfurterCopilot
andcommitted
sdk(rust): Make AttributedDecision a struct-style variant
Hand-written Rust here has 157 enum variants: 89 unit, 35 tuple with exactly one payload, and 33 struct-style. Every variant carrying two or more values uses the struct form, so a two-payload tuple was the only one of its kind. Name the payloads instead. Construction and both read sites now say which value they mean rather than relying on position. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 79152db2-4cc7-4777-983a-655fae5b68c9
1 parent 549c30e commit 277bb6c

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

rust/src/handler.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ pub enum PermissionResult {
4949
///
5050
/// The context is informational only — it never changes permission
5151
/// behavior.
52-
AttributedDecision(PermissionDecision, PermissionDecisionContext),
52+
AttributedDecision {
53+
/// The decision to send on the wire.
54+
decision: PermissionDecision,
55+
/// Context describing how and where the decision was reached.
56+
context: PermissionDecisionContext,
57+
},
5358
/// Decline to respond to this request, allowing another connected
5459
/// client to answer instead. The SDK suppresses the response.
5560
NoResult,
@@ -105,8 +110,8 @@ impl PermissionResult {
105110
/// ```
106111
pub fn with_context(self, context: PermissionDecisionContext) -> Self {
107112
match self {
108-
Self::Decision(decision) | Self::AttributedDecision(decision, _) => {
109-
Self::AttributedDecision(decision, context)
113+
Self::Decision(decision) | Self::AttributedDecision { decision, .. } => {
114+
Self::AttributedDecision { decision, context }
110115
}
111116
Self::NoResult => Self::NoResult,
112117
}

rust/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ fn notification_permission_payload(result: &PermissionResult) -> Option<Value> {
15811581
match result {
15821582
PermissionResult::NoResult => None,
15831583
PermissionResult::Decision(decision)
1584-
| PermissionResult::AttributedDecision(decision, _) => Some(
1584+
| PermissionResult::AttributedDecision { decision, .. } => Some(
15851585
serde_json::to_value(decision).expect("serializing permission decision should succeed"),
15861586
),
15871587
}
@@ -1605,7 +1605,7 @@ fn permission_response_params(
16051605
"requestId": request_id,
16061606
"result": result_value,
16071607
});
1608-
if let PermissionResult::AttributedDecision(_, context) = result {
1608+
if let PermissionResult::AttributedDecision { context, .. } = result {
16091609
params["decisionContext"] =
16101610
serde_json::to_value(context).expect("serializing decision context should succeed");
16111611
}

0 commit comments

Comments
 (0)