pub struct CallPath { /* private fields */ }
Expand description
A parameterized HTTP path with type-safe parameter substitution.
CallPath
represents an HTTP path template with named parameters that can be
substituted with typed values. It supports OpenAPI 3.1 parameter styles and
automatic schema generation.
§Examples
use clawspec_core::{CallPath, ParamValue};
// Create a path template with method chaining
let path = CallPath::from("/users/{user_id}/posts/{post_id}")
.add_param("user_id", ParamValue::new(123))
.add_param("post_id", ParamValue::new("my-post"));
// Path is now ready for resolution to: /users/123/posts/my-post
§Path Template Syntax
Path templates use {parameter_name}
syntax for parameter placeholders.
Parameter names must be valid identifiers (alphanumeric + underscore).
The same parameter can appear multiple times in a single path.
let path = CallPath::from("/api/v1/users/{user_id}/documents/{doc_id}")
.add_param("user_id", ParamValue::new(456))
.add_param("doc_id", ParamValue::new("report-2023"));
// Duplicate parameters are supported
let path = CallPath::from("/test/{id}/{id}")
.add_param("id", ParamValue::new(123));
// Results in: /test/123/123
Implementations§
Source§impl CallPath
impl CallPath
Sourcepub fn add_param<T: ParameterValue>(
self,
name: impl Into<String>,
param: impl Into<ParamValue<T>>,
) -> Self
pub fn add_param<T: ParameterValue>( self, name: impl Into<String>, param: impl Into<ParamValue<T>>, ) -> Self
Adds a path parameter with the given name and value.
This method accepts any value that can be converted into a ParamValue<T>
,
allowing for ergonomic usage where you can pass values directly or use
explicit ParamValue
wrappers for custom styles.
§Parameters
name
: The parameter name (will be converted toString
)param
: The parameter value that can be converted intoParamValue<T>
§Examples
use clawspec_core::{CallPath, ParamValue, ParamStyle};
// Ergonomic usage - pass values directly with method chaining
let path = CallPath::from("/users/{id}")
.add_param("id", 123);
// Explicit ParamValue usage for custom styles
let path = CallPath::from("/users/{id}")
.add_param("id", ParamValue::with_style(456, ParamStyle::Simple));
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CallPath
impl RefUnwindSafe for CallPath
impl Send for CallPath
impl Sync for CallPath
impl Unpin for CallPath
impl UnwindSafe for CallPath
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.