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
Path Safety
In theory object stores support any UTF-8 character sequence, however, certain character sequences cause compatibility problems with some applications and protocols. As such the naming guidelines for S3, GCS and Azure Blob Storage all recommend sticking to a limited character subset.
This presents libraries with two options for consistent path handling:
- Allow constructing unsafe paths, allowing for both reading and writing of data to paths that may not be consistently understood or supported
- Disallow constructing unsafe paths, ensuring data written can be consistently handled by all other systems, but preventing interaction with objects at unsafe paths
This library takes the second approach, in particular:
- Paths are delimited by
/
- Paths do not start with a
/
- Empty path segments are discarded (e.g.
//
is treated as though it were/
) - Relative path segments, i.e.
.
and..
are percent encoded - Unsafe characters are percent encoded, as described by RFC 1738
- All paths are relative to the root of the object store
In order to provide these guarantees there are two ways to safely construct a Path
Encode
A string containing potentially illegal path segments can be encoded to a Path
using Path::from
or Path::from_iter
.
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_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 created from an existing string, returning an
error if it is invalid. Unlike the encoding methods, this will permit
valid percent encoded sequences.
assert_eq!(Path::parse("/foo/foo%2Fbar").unwrap().as_ref(), "foo/foo%2Fbar");
Path::parse("..").unwrap_err();
Path::parse("/foo//").unwrap_err();
Path::parse("😀").unwrap_err();
Implementations
sourceimpl Path
impl Path
sourcepub fn from_filesystem_path(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_filesystem_path(path: impl AsRef<Path>) -> Result<Self, Error>
Convert a filesystem path to a Path
relative to the filesystem root
This will return an error if the path contains illegal character sequences
as defined by Path::parse
or does not exist
Note: this will canonicalize the provided path, resolving any symlinks
sourcepub fn from_absolute_path(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_absolute_path(path: impl AsRef<Path>) -> Result<Self, Error>
Convert an absolute filesystem path to a Path
relative to the filesystem root
This will return an error if the path contains illegal character sequences
as defined by Path::parse
, or base
is not an absolute path
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
sourceimpl<'a, I> FromIterator<I> for Pathwhere
I: Into<PathPart<'a>>,
impl<'a, I> FromIterator<I> for Pathwhere
I: Into<PathPart<'a>>,
sourcefn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl Ord for Path
impl Ord for Path
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Path> for Path
impl PartialEq<Path> for Path
sourceimpl PartialOrd<Path> for Path
impl PartialOrd<Path> for Path
sourcefn partial_cmp(&self, other: &Path) -> Option<Ordering>
fn partial_cmp(&self, other: &Path) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Path
impl StructuralEq for Path
impl StructuralPartialEq for Path
Auto Trait Implementations
impl RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl UnwindSafe for Path
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more