pub struct DataResponse<M>where
M: DataMarker,{
pub metadata: DataResponseMetadata,
pub payload: Option<DataPayload<M>>,
}
Expand description
A response object containing an object as payload and metadata about it.
Fields§
§metadata: DataResponseMetadata
Metadata about the returned object.
payload: Option<DataPayload<M>>
The object itself; None
if it was not loaded.
Implementations§
Source§impl<M> DataResponse<M>where
M: DataMarker,
impl<M> DataResponse<M>where
M: DataMarker,
Sourcepub fn take_payload(self) -> Result<DataPayload<M>, DataError>
pub fn take_payload(self) -> Result<DataPayload<M>, DataError>
Takes ownership of the underlying payload. Error if not present.
To take the metadata, too, use Self::take_metadata_and_payload()
.
Sourcepub fn take_metadata_and_payload(
self,
) -> Result<(DataResponseMetadata, DataPayload<M>), DataError>
pub fn take_metadata_and_payload( self, ) -> Result<(DataResponseMetadata, DataPayload<M>), DataError>
Takes ownership of the underlying metadata and payload. Error if payload is not present.
Sourcepub fn cast<M2>(self) -> DataResponse<M2>where
M2: DataMarker<Yokeable = M::Yokeable>,
pub fn cast<M2>(self) -> DataResponse<M2>where
M2: DataMarker<Yokeable = M::Yokeable>,
Convert between two DataMarker
types that are compatible with each other
with compile-time type checking.
This happens if they both have the same DataMarker::Yokeable
type.
Can be used to erase the key of a data payload in cases where multiple keys correspond to the same data struct.
For runtime dynamic casting, use DataPayload::dynamic_cast_mut()
.
Source§impl<M> DataResponse<M>
impl<M> DataResponse<M>
Sourcepub fn wrap_into_any_response(self) -> AnyResponse
pub fn wrap_into_any_response(self) -> AnyResponse
Moves the inner DataPayload to the heap (requiring an allocation) and returns it as an
erased AnyResponse
.