Struct deltalake::Path

source ·
pub struct Path { /* private fields */ }
Expand description

The deltalake crate is currently just a meta-package shim for deltalake-core 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

source

pub fn parse(path: impl AsRef<str>) -> Result<Path, Error>

Parse a string as a Path, returning a Error if invalid, as defined on the docstring for Path

Note: this will strip any leading / or trailing /

source

pub fn from_filesystem_path(path: impl AsRef<Path>) -> Result<Path, 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 on the docstring for Path or does not exist

Note: this will canonicalize the provided path, resolving any symlinks

source

pub fn from_absolute_path(path: impl AsRef<Path>) -> Result<Path, 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 on the docstring for Path, or base is not an absolute path

source

pub fn from_url_path(path: impl AsRef<str>) -> Result<Path, Error>

Parse a url encoded string as a Path, returning a Error if invalid

This will return an error if the path contains illegal character sequences as defined on the docstring for Path

source

pub fn parts(&self) -> impl Iterator<Item = PathPart<'_>>

Returns the PathPart of this Path

source

pub fn filename(&self) -> Option<&str>

Returns the last path segment containing the filename stored in this Path

source

pub fn extension(&self) -> Option<&str>

Returns the extension of the file stored in this Path, if any

source

pub fn prefix_match( &self, prefix: &Path ) -> Option<impl Iterator<Item = PathPart<'_>>>

Returns an iterator of the PathPart of this Path after prefix

Returns None if the prefix does not match

source

pub fn prefix_matches(&self, prefix: &Path) -> bool

Returns true if this Path starts with prefix

source

pub fn child<'a>(&self, child: impl Into<PathPart<'a>>) -> Path

Creates a new child of this Path

Trait Implementations§

source§

impl AsRef<str> for Path

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl CacheAccessor<Path, Arc<Statistics>> for DefaultFileStatisticsCache

source§

fn get(&self, k: &Path) -> Option<Arc<Statistics>>

Get Statistics for file location.

source§

fn get_with_extra( &self, k: &Path, e: &<DefaultFileStatisticsCache as CacheAccessor<Path, Arc<Statistics>>>::Extra ) -> Option<Arc<Statistics>>

Get Statistics for file location. Returns None if file has changed or not found.

source§

fn put(&self, _key: &Path, _value: Arc<Statistics>) -> Option<Arc<Statistics>>

Save collected file statistics

§

type Extra = ObjectMeta

source§

fn put_with_extra( &self, key: &Path, value: Arc<Statistics>, e: &<DefaultFileStatisticsCache as CacheAccessor<Path, Arc<Statistics>>>::Extra ) -> Option<Arc<Statistics>>

Put value into cache. Returns the old value associated with the key if there was one.
source§

fn remove(&mut self, k: &Path) -> Option<Arc<Statistics>>

Remove an entry from the cache, returning value if they existed in the map.
source§

fn contains_key(&self, k: &Path) -> bool

Check if the cache contains a specific key.
source§

fn len(&self) -> usize

Fetch the total number of cache entries.
source§

fn clear(&self)

Remove all entries from the cache.
source§

fn name(&self) -> String

Return the cache name.
source§

fn is_empty(&self) -> bool

Check if the Cache collection is empty or not.
source§

impl CacheAccessor<Path, Arc<Vec<ObjectMeta>>> for DefaultListFilesCache

§

type Extra = ObjectMeta

source§

fn get(&self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>>

Get value from cache.
source§

fn get_with_extra( &self, _k: &Path, _e: &<DefaultListFilesCache as CacheAccessor<Path, Arc<Vec<ObjectMeta>>>>::Extra ) -> Option<Arc<Vec<ObjectMeta>>>

Get value from cache.
source§

fn put( &self, key: &Path, value: Arc<Vec<ObjectMeta>> ) -> Option<Arc<Vec<ObjectMeta>>>

Put value into cache. Returns the old value associated with the key if there was one.
source§

fn put_with_extra( &self, _key: &Path, _value: Arc<Vec<ObjectMeta>>, _e: &<DefaultListFilesCache as CacheAccessor<Path, Arc<Vec<ObjectMeta>>>>::Extra ) -> Option<Arc<Vec<ObjectMeta>>>

Put value into cache. Returns the old value associated with the key if there was one.
source§

fn remove(&mut self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>>

Remove an entry from the cache, returning value if they existed in the map.
source§

fn contains_key(&self, k: &Path) -> bool

Check if the cache contains a specific key.
source§

fn len(&self) -> usize

Fetch the total number of cache entries.
source§

fn clear(&self)

Remove all entries from the cache.
source§

fn name(&self) -> String

Return the cache name.
source§

fn is_empty(&self) -> bool

Check if the Cache collection is empty or not.
source§

impl Clone for Path

source§

fn clone(&self) -> Path

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Path

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Path

source§

fn default() -> Path

Returns the “default value” for a type. Read more
source§

impl Display for Path

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<&str> for Path

source§

fn from(path: &str) -> Path

Converts to this type from the input type.
source§

impl From<Path> for String

source§

fn from(path: Path) -> String

Converts to this type from the input type.
source§

impl From<String> for Path

source§

fn from(path: String) -> Path

Converts to this type from the input type.
source§

impl<'a, I> FromIterator<I> for Path
where I: Into<PathPart<'a>>,

source§

fn from_iter<T>(iter: T) -> Path
where T: IntoIterator<Item = I>,

Creates a value from an iterator. Read more
source§

impl Hash for Path

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Path

source§

fn cmp(&self, other: &Path) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Path

source§

fn eq(&self, other: &Path) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Path

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Path

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

source§

impl<T> Ungil for T
where T: Send,