pub trait PathBuilder: Sized {
type Input<'a>;
// Required methods
fn select_path(
&self,
input: Self::Input<'_>,
) -> Result<&'static str, IntoHttpError>;
fn all_paths(&self) -> impl Iterator<Item = &'static str>;
// Provided method
fn make_endpoint_url(
&self,
input: Self::Input<'_>,
base_url: &str,
path_args: &[&dyn Display],
query_string: &str,
) -> Result<String, IntoHttpError> { ... }
}api only.Expand description
Trait implemented by types providing a method to construct the path used to query an endpoint.
Types implementing this must enforce that all possible paths returned from select_path() must
contain the same number of variables.
Required Associated Types§
Required Methods§
Sourcefn select_path(
&self,
input: Self::Input<'_>,
) -> Result<&'static str, IntoHttpError>
fn select_path( &self, input: Self::Input<'_>, ) -> Result<&'static str, IntoHttpError>
Pick the right path according to the given input.
Returns an error if no path could be selected for the given input.
Provided Methods§
Sourcefn make_endpoint_url(
&self,
input: Self::Input<'_>,
base_url: &str,
path_args: &[&dyn Display],
query_string: &str,
) -> Result<String, IntoHttpError>
fn make_endpoint_url( &self, input: Self::Input<'_>, base_url: &str, path_args: &[&dyn Display], query_string: &str, ) -> Result<String, IntoHttpError>
Generate the endpoint URL for this data, considering the given input.
§Arguments
input- The input necessary to select the path.base_url- The base URL (i.e. the scheme and host) to which the endpoint path will be appended. Since all paths begin with a slash, it is not necessary for the this to have a trailing slash. If it has one however, it will be ignored.path_args- The values of the variables in the endpoint’s path. The order and number must match the order and number of the variables in the path.query_string- The serialized query string to append to the URL.
§Errors
Returns an error if the PathBuilder::select_path() implementation returns an error.
Panics if the number of path_args doesn’t match the number of variables in the path
returned by PathBuilder::select_path() must contain the same variables.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.