pub struct ResourceResponse<T> { /* private fields */ }Expand description
A response from a REST resource operation.
This wrapper combines the resource data with metadata from the HTTP response, including pagination information and rate limit data.
The struct implements Deref<Target = T> for transparent access to
the inner data. This allows calling methods on T directly through
the response wrapper.
§Type Parameters
T- The type of data contained in the response. For single resources this is the resource type (e.g.,Product). For collections, this isVec<ResourceType>(e.g.,Vec<Product>).
§Example
use shopify_sdk::rest::ResourceResponse;
use shopify_sdk::clients::{ApiCallLimit, PaginationInfo};
// Create a response with a vector of items
let response = ResourceResponse::new(
vec!["item1", "item2", "item3"],
Some(PaginationInfo {
prev_page_info: None,
next_page_info: Some("eyJsYXN0X2lkIjo0fQ".to_string()),
}),
Some(ApiCallLimit { request_count: 1, bucket_size: 40 }),
Some("req-123".to_string()),
);
// Access items via Deref
assert_eq!(response.len(), 3);
assert_eq!(response[0], "item1");
// Access metadata
assert!(response.has_next_page());
assert!(!response.has_prev_page());Implementations§
Source§impl<T> ResourceResponse<T>
impl<T> ResourceResponse<T>
Sourcepub const fn new(
data: T,
pagination: Option<PaginationInfo>,
rate_limit: Option<ApiCallLimit>,
request_id: Option<String>,
) -> Self
pub const fn new( data: T, pagination: Option<PaginationInfo>, rate_limit: Option<ApiCallLimit>, request_id: Option<String>, ) -> Self
Creates a new ResourceResponse with the given data and metadata.
§Arguments
data- The resource datapagination- Pagination info from Link headerrate_limit- Rate limit info from API call limit headerrequest_id- Request ID from X-Request-Id header
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the response and returns the inner data.
Use this when you need ownership of the data and no longer need the response metadata.
§Example
use shopify_sdk::rest::ResourceResponse;
let response = ResourceResponse::new(
vec![1, 2, 3],
None,
None,
None,
);
let data: Vec<i32> = response.into_inner();
assert_eq!(data, vec![1, 2, 3]);Sourcepub const fn data(&self) -> &T
pub const fn data(&self) -> &T
Returns a reference to the inner data.
Note: In most cases, you can use Deref coercion instead of calling this method explicitly.
Sourcepub fn data_mut(&mut self) -> &mut T
pub fn data_mut(&mut self) -> &mut T
Returns a mutable reference to the inner data.
Note: In most cases, you can use DerefMut coercion instead of
calling this method explicitly.
Sourcepub fn has_next_page(&self) -> bool
pub fn has_next_page(&self) -> bool
Returns true if there is a next page of results.
§Example
use shopify_sdk::rest::ResourceResponse;
use shopify_sdk::clients::PaginationInfo;
let response = ResourceResponse::new(
vec!["item"],
Some(PaginationInfo {
prev_page_info: None,
next_page_info: Some("token".to_string()),
}),
None,
None,
);
assert!(response.has_next_page());Sourcepub fn has_prev_page(&self) -> bool
pub fn has_prev_page(&self) -> bool
Returns true if there is a previous page of results.
Sourcepub fn next_page_info(&self) -> Option<&str>
pub fn next_page_info(&self) -> Option<&str>
Returns the page info token for the next page, if available.
Use this token with the page_info query parameter to fetch
the next page of results.
Sourcepub fn prev_page_info(&self) -> Option<&str>
pub fn prev_page_info(&self) -> Option<&str>
Returns the page info token for the previous page, if available.
Sourcepub const fn pagination(&self) -> Option<&PaginationInfo>
pub const fn pagination(&self) -> Option<&PaginationInfo>
Returns the pagination info, if available.
Sourcepub const fn rate_limit(&self) -> Option<&ApiCallLimit>
pub const fn rate_limit(&self) -> Option<&ApiCallLimit>
Returns the rate limit information, if available.
§Example
use shopify_sdk::rest::ResourceResponse;
use shopify_sdk::clients::ApiCallLimit;
let response = ResourceResponse::new(
"data",
None,
Some(ApiCallLimit { request_count: 5, bucket_size: 40 }),
None,
);
let limit = response.rate_limit().unwrap();
assert_eq!(limit.request_count, 5);
assert_eq!(limit.bucket_size, 40);Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Returns the request ID from the response headers.
Useful for debugging and error reporting.
Sourcepub fn map<U, F>(self, f: F) -> ResourceResponse<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> ResourceResponse<U>where
F: FnOnce(T) -> U,
Maps the inner data to a new type.
Useful for transforming the response data while preserving metadata.
Source§impl<T: DeserializeOwned> ResourceResponse<T>
impl<T: DeserializeOwned> ResourceResponse<T>
Sourcepub fn from_http_response(
response: HttpResponse,
key: &str,
) -> Result<Self, ResourceError>
pub fn from_http_response( response: HttpResponse, key: &str, ) -> Result<Self, ResourceError>
Creates a ResourceResponse from an HTTP response.
Extracts the data from the response body under the given key, along with pagination and rate limit information.
§Arguments
response- The HTTP responsekey- The key in the response body containing the data
§Errors
Returns ResourceError::Http if the data cannot be deserialized.
§Example
use shopify_sdk::rest::ResourceResponse;
// Assuming response.body = {"product": {"id": 123, "title": "Test"}}
let response: ResourceResponse<Product> = ResourceResponse::from_http_response(
http_response,
"product",
)?;Trait Implementations§
Source§impl<T: Clone> Clone for ResourceResponse<T>
impl<T: Clone> Clone for ResourceResponse<T>
Source§fn clone(&self) -> ResourceResponse<T>
fn clone(&self) -> ResourceResponse<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for ResourceResponse<T>
impl<T: Debug> Debug for ResourceResponse<T>
Source§impl<T> Deref for ResourceResponse<T>
Provides transparent access to the inner data.
impl<T> Deref for ResourceResponse<T>
Provides transparent access to the inner data.
This allows methods of T to be called directly on ResourceResponse<T>.