pub trait NamedCookie: Sized + Send {
const COOKIE_NAME: &'static str;
// Required method
fn from_value(value: &str) -> Result<Self, String>;
}Expand description
Trait for types that extract a specific named cookie.
§Example
use typeway_server::extract::{Cookie, NamedCookie};
struct SessionId(String);
impl NamedCookie for SessionId {
const COOKIE_NAME: &'static str = "session_id";
fn from_value(value: &str) -> Result<Self, String> {
Ok(SessionId(value.to_string()))
}
}
async fn handler(Cookie(session): Cookie<SessionId>) -> String {
format!("session: {}", session.0)
}Required Associated Constants§
Sourceconst COOKIE_NAME: &'static str
const COOKIE_NAME: &'static str
The cookie name to extract.
Required Methods§
Sourcefn from_value(value: &str) -> Result<Self, String>
fn from_value(value: &str) -> Result<Self, String>
Parse the cookie value string into this type.
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.