Skip to content

Commit

Permalink
refactor(headers): Implement Display trait for Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Wong committed Jan 4, 2025
1 parent 077e711 commit 63644c9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/http/headers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};

use super::common::CRLF;

Expand Down Expand Up @@ -41,11 +41,14 @@ impl FromIterator<String> for Headers {
}
}

impl ToString for Headers {
fn to_string(&self) -> String {
self.0
.iter()
.map(|(key, value)| format!("{key}: {value}{CRLF}"))
.collect::<String>()
impl Display for Headers {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(
&self
.0
.iter()
.map(|(key, value)| format!("{key}: {value}{CRLF}"))
.collect::<String>(),
)
}
}

0 comments on commit 63644c9

Please sign in to comment.