Struct object_store::path::Path
source · pub struct Path { /* private fields */ }
Expand description
A parsed path representation that can be safely written to object storage
A Path
maintains the following invariants:
- Paths are delimited by
/
- Paths do not contain leading or trailing
/
- Paths do not contain relative path segments, i.e.
.
or..
- Paths do not contain empty path segments
- Paths do not contain any ASCII control characters
There are no enforced restrictions on path length, however, it should be noted that most object stores do not permit paths longer than 1024 bytes, and many filesystems do not support path segments longer than 255 bytes.
§Encode
In theory object stores support any UTF-8 character sequence, however, certain character
sequences cause compatibility problems with some applications and protocols. Additionally
some filesystems may impose character restrictions, see LocalFileSystem
. As such the
naming guidelines for S3, GCS and Azure Blob Storage all recommend sticking to a
limited character subset.
A string containing potentially problematic path segments can therefore be encoded to a Path
using Path::from
or Path::from_iter
. This will percent encode any problematic
segments according to RFC 1738.
assert_eq!(Path::from("foo/bar").as_ref(), "foo/bar");
assert_eq!(Path::from("foo//bar").as_ref(), "foo/bar");
assert_eq!(Path::from("foo/../bar").as_ref(), "foo/%2E%2E/bar");
assert_eq!(Path::from("/").as_ref(), "");
assert_eq!(Path::from_iter(["foo", "foo/bar"]).as_ref(), "foo/foo%2Fbar");
Note: if provided with an already percent encoded string, this will encode it again
assert_eq!(Path::from("foo/foo%2Fbar").as_ref(), "foo/foo%252Fbar");
§Parse
Alternatively a Path
can be parsed from an existing string, returning an
error if it is invalid. Unlike the encoding methods above, this will permit
arbitrary unicode, including percent encoded sequences.
assert_eq!(Path::parse("/foo/foo%2Fbar").unwrap().as_ref(), "foo/foo%2Fbar");
Path::parse("..").unwrap_err(); // Relative path segments are disallowed
Path::parse("/foo//").unwrap_err(); // Empty path segments are disallowed
Path::parse("\x00").unwrap_err(); // ASCII control characters are disallowed
Implementations§
source§impl Path
impl Path
sourcepub fn filename(&self) -> Option<&str>
pub fn filename(&self) -> Option<&str>
Returns the last path segment containing the filename stored in this Path
sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Returns the extension of the file stored in this Path
, if any
sourcepub fn prefix_match(
&self,
prefix: &Self,
) -> Option<impl Iterator<Item = PathPart<'_>> + '_>
pub fn prefix_match( &self, prefix: &Self, ) -> Option<impl Iterator<Item = PathPart<'_>> + '_>
sourcepub fn prefix_matches(&self, prefix: &Self) -> bool
pub fn prefix_matches(&self, prefix: &Self) -> bool
Returns true if this Path
starts with prefix
Trait Implementations§
source§impl<'a, I> FromIterator<I> for Path
impl<'a, I> FromIterator<I> for Path
source§fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self
source§impl Ord for Path
impl Ord for Path
source§impl PartialOrd for Path
impl PartialOrd for Path
impl Eq for Path
impl StructuralPartialEq for Path
Auto Trait Implementations§
impl Freeze for Path
impl RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl UnwindSafe for Path
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more