better_url/parts/path/entire/
opaque.rs1use crate::prelude::*;
4
5#[derive(Debug, Clone)]
13pub struct OpaquePath<'a>(Cow<'a, str>);
14
15impl<'a> OpaquePath<'a> {
16 pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {
20 Self(value.into())
21 }
22
23 pub fn as_str(&self) -> &str {
25 &self.0
26 }
27
28
29
30
31 pub fn into_inner(self) -> Cow<'a, str> {
33 self.0
34 }
35
36 pub fn into_owned(self) -> OpaquePath<'static> {
38 OpaquePath(self.0.into_owned().into())
39 }
40
41 pub fn borrowed(&self) -> OpaquePath<'_> {
43 OpaquePath(Cow::Borrowed(&self.0))
44 }
45}
46
47
48
49impl<'a> From<Cow<'a, [u8]>> for OpaquePath<'a> {
50 fn from(value: Cow<'a, [u8]>) -> Self {
51 let (_, value) = make_opaque_path_bytes(value);
52
53 unsafe {
54 Self::new_unchecked(value)
55 }
56 }
57}
58
59
60
61impl<'a> From<Path<'a>> for OpaquePath<'a> {
62 fn from(value: Path<'a>) -> Self {
63 match value {
64 Path::Segmented(x) => x.into(),
65 Path::Opaque (x) => x,
66 }
67 }
68}
69
70impl<'a> From<SegmentedPath <'a>> for OpaquePath<'a> {fn from(value: SegmentedPath <'a>) -> Self {Self(segmented_path_to_opaque_path(value.into_inner()).1)}}
71impl<'a> From<FilePath <'a>> for OpaquePath<'a> {fn from(value: FilePath <'a>) -> Self {Self(segmented_path_to_opaque_path(value.into_inner()).1)}}
72impl<'a> From<SpecialNotFilePath<'a>> for OpaquePath<'a> {fn from(value: SpecialNotFilePath<'a>) -> Self {Self(segmented_path_to_opaque_path(value.into_inner()).1)}}
73impl<'a> From<NonSpecialPath <'a>> for OpaquePath<'a> {fn from(value: NonSpecialPath <'a>) -> Self {Self(segmented_path_to_opaque_path(value.into_inner()).1)}}