#[non_exhaustive]pub struct OpResult {
pub op_index: usize,
pub outcome: Result<Option<Id>, SetError>,
}Expand description
The outcome of a single SpacePatchOp applied by
ChatSpaces::apply_space_patch.
op_index is the zero-based index of the op within the input Vec, used
by handlers to construct a descriptive error message identifying which
per-key entry failed (e.g. addRoles[2] failed: ...).
outcome is:
Ok(Some(id))— the op produced a new server-assigned id (e.g.SpacePatchOp::AddRole,SpacePatchOp::AddChannel,SpacePatchOp::AddCategory). The handler reports this id back to the client via the/setresponse.Ok(None)— the op completed but produced no id (everyRemove*andUpdate*variant).Err(SetError)— the op was rejected (e.g. permission denied, target id not found, role hierarchy violation, count limit exceeded).
Per RFC 8620 §5.3 /set, an update target is per-target atomic on the
wire: it appears in exactly one of updated or notUpdated. If any
OpResult in the returned Vec has an Err, the handler reports the
containing update target in notUpdated. The handler is free to choose
which Err to surface; the reference handler surfaces the first.
This type lives in jmap-chat-server (not jmap-chat-types) because
SetError is defined in jmap-server and jmap-chat-types cannot
depend on it (per the workspace dependency rule: types crates depend
only on jmap-types, serde, serde_json).
#[non_exhaustive] preserves the ability to add fields without a
SemVer break (e.g. an audit-log handle, commit ordering hint,
permission-diagnostic annotation). External consumers MUST construct
instances via OpResult::ok or OpResult::err rather than
field-init syntax.
§Field-addition policy
Future fields added to OpResult are an additive non-breaking
change: the new field MUST have a Default value (typical for
Option / Vec / HashMap) and the new field is exposed via a
with_*-style builder setter rather than being appended as a third
positional argument to OpResult::ok or OpResult::err. The
ok(op_index, id) and err(op_index, error) constructors therefore
stay stable across the crate’s pre-1.0 lifetime, matching the
ChatLimits-style canonical workspace pattern for
#[non_exhaustive] types with builder setters.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.op_index: usizeZero-based index of the originating op in the input Vec<SpacePatchOp>.
outcome: Result<Option<Id>, SetError>The outcome of applying that op.
Implementations§
Source§impl OpResult
impl OpResult
Sourcepub const fn ok(op_index: usize, id: Option<Id>) -> Self
pub const fn ok(op_index: usize, id: Option<Id>) -> Self
Construct an Ok result for a successfully applied op.
The contained Id is the server-assigned id when the op was a
create (the kit’s response includes it under created[create_id].id);
pass None for updates and destroys, which have no id to surface.
Sourcepub const fn err(op_index: usize, error: SetError) -> Self
pub const fn err(op_index: usize, error: SetError) -> Self
Construct an Err result for a rejected op.
The kit’s handle_space_set surfaces this error to the JMAP
notUpdated map for the containing update target.
Sourcepub const fn with_op_index(self, op_index: usize) -> Self
pub const fn with_op_index(self, op_index: usize) -> Self
Builder-style setter for Self::op_index.
Lets callers update the originating op index after construction. Useful when re-indexing a result produced for one op into the position of another (e.g. when filtering a batch).
Sourcepub fn with_outcome(self, outcome: Result<Option<Id>, SetError>) -> Self
pub fn with_outcome(self, outcome: Result<Option<Id>, SetError>) -> Self
Builder-style setter for Self::outcome.
Lets callers replace the outcome after construction. Useful for retry / fallback flows that re-classify a transient error into a success or vice versa before surfacing the result to the handler.