diff options
| author | Fuwn <[email protected]> | 2023-04-02 02:06:25 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-02 02:06:25 +0000 |
| commit | 15923b95c9466d9165e540238184eef18bf80a7f (patch) | |
| tree | 39e715a56465578dc869608bb8facb3dfe29aaca /src/response.rs | |
| parent | feat(response): add 'auto' functionality to binary_success raw (diff) | |
| download | windmark-15923b95c9466d9165e540238184eef18bf80a7f.tar.xz windmark-15923b95c9466d9165e540238184eef18bf80a7f.zip | |
feat(response): allow multiple languages
Diffstat (limited to 'src/response.rs')
| -rw-r--r-- | src/response.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/response.rs b/src/response.rs index 6feecf5..2a615a7 100644 --- a/src/response.rs +++ b/src/response.rs @@ -37,7 +37,7 @@ pub struct Response { pub mime: Option<String>, pub content: String, pub character_set: Option<String>, - pub language: Option<String>, + pub languages: Option<Vec<String>>, } impl Response { @@ -79,7 +79,7 @@ impl Response { pub fn success(content: impl ToString) -> Self { Self::new(20, content.to_string()) .with_mime("text/gemini") - .with_language("en") + .with_languages(["en"]) .with_character_set("utf-8") .clone() } @@ -109,7 +109,7 @@ impl Response { mime: None, content: content.into(), character_set: None, - language: None, + languages: None, } } @@ -131,11 +131,15 @@ impl Response { self } - pub fn with_language( - &mut self, - language: impl Into<String> + AsRef<str>, - ) -> &mut Self { - self.language = Some(language.into()); + pub fn with_languages<S>(&mut self, languages: impl AsRef<[S]>) -> &mut Self + where S: Into<String> + AsRef<str> { + self.languages = Some( + languages + .as_ref() + .iter() + .map(|s| s.as_ref().to_string()) + .collect::<Vec<String>>(), + ); self } |