Add basic codes

This commit is contained in:
2026-08-18 13:41:49 +08:00
parent 0173669e23
commit a5e55d4355
6 changed files with 498 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
use std::str::FromStr;
#[derive(Debug)]
pub(crate) struct ReqLine {
pub(crate) method: String,
pub(crate) route: String,
pub(crate) version: String,
}
impl FromStr for ReqLine {
type Err = std::io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (method, rest) = s
.split_once(" ")
.ok_or(std::io::Error::other("Missing route"))?;
let (route, version) = rest
.split_once(" ")
.ok_or(std::io::Error::other("Missing version"))?;
Ok(Self {
method: method.trim().to_string(),
route: route.trim().to_string(),
version: version.trim().to_string(),
})
}
}
#[derive(Debug)]
pub(crate) struct Header {
pub(crate) key: String,
pub(crate) value: String,
}
impl FromStr for Header {
type Err = std::io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (key, value) = s
.split_once(":")
.ok_or(std::io::Error::other("Missing value"))?;
Ok(Self {
key: key.trim().to_string(),
value: value.trim().to_string(),
})
}
}