pub struct BrowseParams { /* private fields */ }Expand description
Fluent builder for Ghost API browse query parameters.
All setter methods consume and return self so calls can be chained.
Fields left unset are omitted from the query string entirely, letting
Ghost apply its own defaults.
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new()
.limit(5)
.filter("featured:true")
.order("published_at DESC");
let pairs = params.to_query_pairs();
let map: std::collections::HashMap<_, _> = pairs.into_iter().collect();
assert_eq!(map["limit"], "5");
assert_eq!(map["filter"], "featured:true");Implementations§
Source§impl BrowseParams
impl BrowseParams
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new BrowseParams with no fields set.
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new();
assert!(params.to_query_pairs().is_empty());Sourcepub fn limit(self, limit: u32) -> Self
pub fn limit(self, limit: u32) -> Self
Sets the maximum number of results per page.
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().limit(15);
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("limit", "15".to_string()));Sourcepub fn page(self, page: u32) -> Self
pub fn page(self, page: u32) -> Self
Sets the page number to retrieve (1-indexed).
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().page(3);
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("page", "3".to_string()));Sourcepub fn filter(self, filter: impl Into<String>) -> Self
pub fn filter(self, filter: impl Into<String>) -> Self
Sets the Ghost filter expression.
See the Ghost filter docs
for the full syntax. Examples: "featured:true", "tag:getting-started",
"published_at:>2020-01-01".
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().filter("featured:true");
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("filter", "featured:true".to_string()));Sourcepub fn order(self, order: impl Into<String>) -> Self
pub fn order(self, order: impl Into<String>) -> Self
Sets the sort order.
Accepts a comma-separated list of <field> <direction> clauses,
e.g. "published_at DESC,title ASC".
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().order("published_at DESC");
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("order", "published_at DESC".to_string()));Sourcepub fn include(self, include: impl Into<String>) -> Self
pub fn include(self, include: impl Into<String>) -> Self
Sets the relations to include in the response.
Accepts a comma-separated list of relation names supported by the
endpoint, e.g. "authors,tags".
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().include("authors,tags");
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("include", "authors,tags".to_string()));Sourcepub fn fields(self, fields: impl Into<String>) -> Self
pub fn fields(self, fields: impl Into<String>) -> Self
Sets the fields to return in each result object.
Accepts a comma-separated list of field names, e.g. "id,title,slug".
Unlisted fields are omitted from the response.
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().fields("id,title,slug");
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("fields", "id,title,slug".to_string()));Sourcepub fn formats(self, formats: impl Into<String>) -> Self
pub fn formats(self, formats: impl Into<String>) -> Self
Sets the content formats to return.
Accepts a comma-separated list of format names. Valid values are
"html", "mobiledoc", "lexical", and "plaintext".
§Example
use ghost_io_api::params::browse::BrowseParams;
let params = BrowseParams::new().formats("html,plaintext");
let pairs = params.to_query_pairs();
assert_eq!(pairs[0], ("formats", "html,plaintext".to_string()));Sourcepub fn get_filter(&self) -> Option<&str>
pub fn get_filter(&self) -> Option<&str>
Returns the current filter value, if set.
Sourcepub fn get_include(&self) -> Option<&str>
pub fn get_include(&self) -> Option<&str>
Returns the current include value, if set.
Sourcepub fn get_fields(&self) -> Option<&str>
pub fn get_fields(&self) -> Option<&str>
Returns the current fields value, if set.
Sourcepub fn get_formats(&self) -> Option<&str>
pub fn get_formats(&self) -> Option<&str>
Returns the current formats value, if set.
Sourcepub fn to_query_pairs(&self) -> Vec<(&'static str, String)>
pub fn to_query_pairs(&self) -> Vec<(&'static str, String)>
Serialises the parameters as a Vec of (name, value) string pairs.
Only fields that have been set are included. The order is stable:
limit, page, filter, order, include, fields, formats.
Suitable for passing directly to reqwest’s .query() method.
§Example
use ghost_io_api::params::browse::BrowseParams;
let pairs = BrowseParams::new()
.limit(5)
.page(1)
.to_query_pairs();
assert_eq!(pairs.len(), 2);
assert_eq!(pairs[0], ("limit", "5".to_string()));
assert_eq!(pairs[1], ("page", "1".to_string()));Sourcepub fn to_query_string(&self) -> String
pub fn to_query_string(&self) -> String
Serialises the parameters as a URL query string (without leading ?).
Fields are percent-encoded. Returns an empty string when no fields are set.
§Example
use ghost_io_api::params::browse::BrowseParams;
let qs = BrowseParams::new()
.limit(10)
.filter("featured:true")
.to_query_string();
assert!(qs.contains("limit=10"));
assert!(qs.contains("filter=featured%3Atrue"));Trait Implementations§
Source§impl Clone for BrowseParams
impl Clone for BrowseParams
Source§fn clone(&self) -> BrowseParams
fn clone(&self) -> BrowseParams
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BrowseParams
impl Debug for BrowseParams
Source§impl Default for BrowseParams
impl Default for BrowseParams
Source§fn default() -> BrowseParams
fn default() -> BrowseParams
impl Eq for BrowseParams
Source§impl PartialEq for BrowseParams
impl PartialEq for BrowseParams
Source§fn eq(&self, other: &BrowseParams) -> bool
fn eq(&self, other: &BrowseParams) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for BrowseParams
Auto Trait Implementations§
impl Freeze for BrowseParams
impl RefUnwindSafe for BrowseParams
impl Send for BrowseParams
impl Sync for BrowseParams
impl Unpin for BrowseParams
impl UnsafeUnpin for BrowseParams
impl UnwindSafe for BrowseParams
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.