Skip to main content

BrowseParams

Struct BrowseParams 

Source
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

Source

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());
Source

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()));
Source

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()));
Source

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()));
Source

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()));
Source

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()));
Source

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()));
Source

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()));
Source

pub fn get_limit(&self) -> Option<u32>

Returns the current limit value, if set.

Source

pub fn get_page(&self) -> Option<u32>

Returns the current page value, if set.

Source

pub fn get_filter(&self) -> Option<&str>

Returns the current filter value, if set.

Source

pub fn get_order(&self) -> Option<&str>

Returns the current order value, if set.

Source

pub fn get_include(&self) -> Option<&str>

Returns the current include value, if set.

Source

pub fn get_fields(&self) -> Option<&str>

Returns the current fields value, if set.

Source

pub fn get_formats(&self) -> Option<&str>

Returns the current formats value, if set.

Source

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()));
Source

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

Source§

fn clone(&self) -> BrowseParams

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BrowseParams

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BrowseParams

Source§

fn default() -> BrowseParams

Returns the “default value” for a type. Read more
Source§

impl Eq for BrowseParams

Source§

impl PartialEq for BrowseParams

Source§

fn eq(&self, other: &BrowseParams) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BrowseParams

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more