-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e476dd9
commit dfe83cf
Showing
3 changed files
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
use crate::{decode::percent_decode, errors::decode::DecodeError}; | ||
use std::borrow::Cow; | ||
|
||
pub struct Path { | ||
pub inner: Vec<u8>, | ||
pub struct Path<'a> { | ||
original: Cow<'a, [u8]>, | ||
decoded: Option<Vec<u8>>, | ||
} | ||
|
||
impl Path { | ||
impl<'a> Path<'a> { | ||
#[must_use] | ||
pub fn new(path: &str) -> Self { | ||
pub const fn new(path: &'a str) -> Self { | ||
Self { | ||
inner: path.as_bytes().to_vec(), | ||
original: Cow::Borrowed(path.as_bytes()), | ||
decoded: None, | ||
} | ||
} | ||
|
||
pub fn percent_decode(&mut self) -> Result<(), DecodeError> { | ||
self.inner = percent_decode(&self.inner)?; | ||
if self.decoded.is_none() { | ||
self.decoded = Some(percent_decode(&self.original)?); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[must_use] | ||
pub fn as_bytes(&self) -> &[u8] { | ||
self.decoded.as_deref().unwrap_or(&self.original) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters