aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-06-19 06:46:20 +0000
committerFuwn <[email protected]>2024-06-19 06:52:44 +0000
commita385a6d207bc8337029482474503d0e3fae2d44c (patch)
treef91e3d8734364aa68240484d8883e4e3a67c9e6e /src
parentfix(tests): blocking and non-blocking request (diff)
downloadgerm-a385a6d207bc8337029482474503d0e3fae2d44c.tar.xz
germ-a385a6d207bc8337029482474503d0e3fae2d44c.zip
deps(rustc): bump rust toolchain
Diffstat (limited to 'src')
-rw-r--r--src/meta.rs19
-rw-r--r--src/request/response.rs12
2 files changed, 14 insertions, 17 deletions
diff --git a/src/meta.rs b/src/meta.rs
index 1991d3a..e9a80f1 100644
--- a/src/meta.rs
+++ b/src/meta.rs
@@ -16,7 +16,7 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{borrow::Cow, collections::HashMap};
+use std::{borrow::Cow, collections::HashMap, fmt::Display};
/// Structure-ize a Gemini response's meta section into it's mime type and it's
/// parameters.
@@ -28,20 +28,9 @@ pub struct Meta {
parameters: HashMap<String, String>,
}
-impl ToString for Meta {
- /// Convert a `Meta` into a `String`
- ///
- /// # Example
- /// ```rust
- /// let original_string = "text/gemini; hi=2; hi2=string=2";
- ///
- /// assert_eq!(
- /// germ::meta::Meta::from_string(original_string).to_string(),
- /// original_string
- /// );
- /// ```
- fn to_string(&self) -> String {
- format!("{}{}", self.mime, {
+impl Display for Meta {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}{}", self.mime, {
let mut parameters = self
.parameters
.iter()
diff --git a/src/request/response.rs b/src/request/response.rs
index f0119d0..c676d28 100644
--- a/src/request/response.rs
+++ b/src/request/response.rs
@@ -16,7 +16,11 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use {crate::request::Status, rustls::SupportedCipherSuite, std::borrow::Cow};
+use {
+ crate::request::Status,
+ rustls::SupportedCipherSuite,
+ std::{borrow::Cow, fmt::Write},
+};
#[derive(Debug, Clone)]
pub struct Response {
@@ -39,7 +43,11 @@ impl Response {
let mut string_split = string_form.split("\r\n");
header = string_split.next().unwrap_or("").to_string();
- content = Some(string_split.map(|s| format!("{s}\r\n")).collect());
+ content = Some(string_split.fold(String::new(), |mut output, s| {
+ let _ = write!(output, "{s}\r\n");
+
+ output
+ }));
}
let header_split = header.split_at(2);