Skip to main content

BusHttpExt

Trait BusHttpExt 

Source
pub trait BusHttpExt {
    // Required methods
    fn path_param<T: FromStr>(&self, name: &str) -> Result<T, String>;
    fn query_param<T: FromStr>(&self, name: &str) -> Option<T>;
    fn query_param_or<T: FromStr>(&self, name: &str, default: T) -> T;
}
Expand description

HTTP-specific convenience methods for Bus.

Import this trait to access path/query parameter extraction directly from the Bus.

§Example

use ranvier_http::BusHttpExt;
use uuid::Uuid;

let id: Uuid = ranvier_core::try_outcome!(bus.path_param("id"), "path");
let page: i64 = bus.query_param_or("page", 1);

Required Methods§

Source

fn path_param<T: FromStr>(&self, name: &str) -> Result<T, String>

Extract and parse a path parameter from the Bus.

Looks up PathParams in the Bus, then parses the named parameter as T.

Returns Err if:

  • PathParams is not in the Bus
  • The named key does not exist in PathParams
  • The value cannot be parsed as T
§Example
use ranvier_http::BusHttpExt;
use uuid::Uuid;

// Inside a transition:
let id: Uuid = ranvier_core::try_outcome!(bus.path_param("id"), "path");
Source

fn query_param<T: FromStr>(&self, name: &str) -> Option<T>

Extract and parse a query parameter from the Bus.

Returns None if QueryParams is missing, the key is absent, or parsing fails.

§Example
use ranvier_http::BusHttpExt;

let page: Option<i64> = bus.query_param("page");
Source

fn query_param_or<T: FromStr>(&self, name: &str, default: T) -> T

Extract and parse a query parameter, or return a default value.

§Example
use ranvier_http::BusHttpExt;

let page: i64 = bus.query_param_or("page", 1);
let per_page: i64 = bus.query_param_or("per_page", 20);

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.

Implementations on Foreign Types§

Source§

impl BusHttpExt for Bus

Source§

fn path_param<T: FromStr>(&self, name: &str) -> Result<T, String>

Source§

fn query_param<T: FromStr>(&self, name: &str) -> Option<T>

Source§

fn query_param_or<T: FromStr>(&self, name: &str, default: T) -> T

Implementors§