pub struct Path<T>(pub T)
where
T: DeserializeOwned;
Expand description
A path extractor that captures a given type from a frame. This is used to extract path captures from a message frame’s URI, turning them into local types. It obeys a few rules:
- It must be used with a list-friendly type, such as
Path<(String,)>
. This is because, under the hood, it grabs a list of all path captures and then deserializes them into the given types. That means it’s always expecting some kind of list type. If all the types are uniform, you can use a Vec or an array. - If it’s a tuple, the number of types must match the number of captures in the path. If it’s a list, the number of types must be equal to or less than the number of captures in the path.
- The given type must be deserializable from the captures. This means that
the type must implement
DeserializeOwned
or ‘Deserialize’.
If any of these rules are broken, the extractor will fail to extract with a runtime rejection.
§Example
use intrepid::{Path, Frame, System, Action};
#[tokio::main]
async fn main() -> intrepid::Result<()> {
let system = System::routed().on("/uri/:id", |Path((id,)): Path<(uuid::Uuid,)>| async { id });
let id = uuid::Uuid::new_v4();
let response = system.call(Frame::message(format!("/uri/{id}")).await?;
assert_eq!(response, id);
}
Tuple Fields§
§0: T
Trait Implementations§
Source§impl<State, T> Extractor<State> for Path<T>
impl<State, T> Extractor<State> for Path<T>
Source§type Error = PathError
type Error = PathError
The error type for this extractor. Anything that can be converted into an extractor error
can be used as an error type. Read more
Source§fn extract(frame: Frame, context: &Context<State>) -> Result<Self, Self::Error>
fn extract(frame: Frame, context: &Context<State>) -> Result<Self, Self::Error>
Take an frame and a state and return a result containing the extracted value or the frame.
impl<T> Eq for Path<T>where
T: DeserializeOwned + Eq,
impl<T> StructuralPartialEq for Path<T>where
T: DeserializeOwned,
Auto Trait Implementations§
impl<T> Freeze for Path<T>where
T: Freeze,
impl<T> RefUnwindSafe for Path<T>where
T: RefUnwindSafe,
impl<T> Send for Path<T>where
T: Send,
impl<T> Sync for Path<T>where
T: Sync,
impl<T> Unpin for Path<T>where
T: Unpin,
impl<T> UnwindSafe for Path<T>where
T: UnwindSafe,
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