pub struct SingleEnvelope<T> {
pub item: T,
}Expand description
Response envelope for Ghost read, create, and update endpoints.
These endpoints return {"<resource>": [item]} — a one-element array
wrapped in a resource-keyed object, with no "meta" block. SingleEnvelope
deserializes any such object, extracts the first element of the array, and
stores it as item.
As with BrowseEnvelope, the resource key ("posts", "pages", …) is
detected automatically; no per-resource specialisation is required.
§Fields
item— the single deserialized resource object.
§Errors
Deserialization fails if the JSON object contains no array-valued field, or if that array is empty.
§Example
use ghost_io_api::models::envelope::SingleEnvelope;
use serde::Deserialize;
use serde_json::json;
#[derive(Debug, Deserialize)]
struct Post { id: String, title: String }
// Read by ID
let json = json!({"posts": [{"id": "abc", "title": "Hello"}]});
let env: SingleEnvelope<Post> = serde_json::from_value(json).unwrap();
assert_eq!(env.item.id, "abc");
assert_eq!(env.item.title, "Hello");Fields§
§item: TThe single resource item extracted from the array.
Trait Implementations§
Source§impl<T: Clone> Clone for SingleEnvelope<T>
impl<T: Clone> Clone for SingleEnvelope<T>
Source§fn clone(&self) -> SingleEnvelope<T>
fn clone(&self) -> SingleEnvelope<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for SingleEnvelope<T>
impl<T: Debug> Debug for SingleEnvelope<T>
Source§impl<'de, T: DeserializeOwned> Deserialize<'de> for SingleEnvelope<T>
impl<'de, T: DeserializeOwned> Deserialize<'de> for SingleEnvelope<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for SingleEnvelope<T>where
T: Freeze,
impl<T> RefUnwindSafe for SingleEnvelope<T>where
T: RefUnwindSafe,
impl<T> Send for SingleEnvelope<T>where
T: Send,
impl<T> Sync for SingleEnvelope<T>where
T: Sync,
impl<T> Unpin for SingleEnvelope<T>where
T: Unpin,
impl<T> UnsafeUnpin for SingleEnvelope<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for SingleEnvelope<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more