Skip to main content

OpResult

Struct OpResult 

Source
#[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 ChatBackend::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 /set response.
  • Ok(None) — the op completed but produced no id (every Remove* and Update* 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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§op_index: usize

Zero-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

Source

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.

Source

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.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Debug for OpResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more