Skip to main content

nextcloud_ocs/envelope/
ocs_envelope.rs

1use serde::{Deserialize, Serialize};
2
3use super::{Meta, Ocs};
4
5/// Top level of every JSON OCS response: `{"ocs": {...}}`.
6///
7/// The wrapper exists because OCS also answers in XML, where the same shape
8/// appears as an `ocs` element; the name is part of the wire format, not a
9/// decoration. A response without it is a decode failure, not an empty
10/// payload.
11#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
12pub struct OcsEnvelope<T> {
13    ocs: Ocs<T>,
14}
15
16impl<T> OcsEnvelope<T> {
17    /// The wrapped [`Ocs`] block.
18    pub const fn ocs(&self) -> &Ocs<T> {
19        &self.ocs
20    }
21
22    /// Verdict and pagination hints for this response.
23    pub const fn meta(&self) -> &Meta {
24        self.ocs.meta()
25    }
26
27    /// Payload returned by the endpoint.
28    pub const fn data(&self) -> &T {
29        self.ocs.data()
30    }
31
32    /// Consumes the envelope, yielding the payload.
33    pub fn into_data(self) -> T {
34        self.ocs.into_data()
35    }
36}