MCPcopy Create free account
hub / github.com/actix/examples / from_req

Method from_req

templating/fluent/src/lang_choice.rs:17–24  ·  view source on GitHub ↗
(req: &HttpRequest)

Source from the content-addressed store, hash-verified

15
16impl LangChoice {
17 pub(crate) fn from_req(req: &HttpRequest) -> Self {
18 let lang = req
19 .get_header::<AcceptLanguage>()
20 .and_then(|lang| lang.preference().into_item())
21 .map_or_else(|| "en".to_owned(), |lang| lang.to_string());
22
23 Self(lang)
24 }
25
26 pub fn lang_id(&self) -> LanguageIdentifier {
27 // unwrap: lang ID should be valid given extraction method

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected