pub struct S3PathBuf { /* private fields */ }
Expand description
An owned S3 storage path.
Implementations§
Source§impl S3PathBuf
impl S3PathBuf
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty S3 path. Call join
or push
to extend it with additional path segments.
Sourcepub fn try_from<C: Into<Cow<'static, str>>, I: IntoIterator<Item = C>>(
components: I,
) -> Result<Self, InvalidS3PathComponent>
pub fn try_from<C: Into<Cow<'static, str>>, I: IntoIterator<Item = C>>( components: I, ) -> Result<Self, InvalidS3PathComponent>
Validates and adds all components
to the returned S3PathBuf
.
NO component is parsed for slashes (‘/’) to be split up further!
§Errors
Returns Err
when any given component
- is empty
- contains characters other than: ascii alphanumeric characters, ‘-’, ‘_’ and ‘.’
- is equal to
.
or..
Sourcepub fn try_from_str(
string: impl AsRef<str>,
) -> Result<Self, InvalidS3PathComponent>
pub fn try_from_str( string: impl AsRef<str>, ) -> Result<Self, InvalidS3PathComponent>
Splits string
at each occurrence of a /
, then validates and add all components to the
returned S3PathBuf
.
Multiple consecutive slashes, as in “foo//bar”, are treated as one.
§Errors
Returns Err
when any component read
- contains characters other than: ascii alphanumeric characters, ‘-’, ‘_’ and ‘.’
- is equal to
.
or..
Sourcepub fn extend(
&mut self,
addition: impl Into<Cow<'static, str>>,
) -> Result<&mut Self, InvalidS3PathComponent>
pub fn extend( &mut self, addition: impl Into<Cow<'static, str>>, ) -> Result<&mut Self, InvalidS3PathComponent>
Extend the last component of the path, if there is one, with [addition].
If this path is empty, pushes [addition] the initial path component instead.
use s3_path::S3PathBuf;
let mut file = S3PathBuf::try_from_str("my/file").unwrap();
file.extend(".txt").unwrap();
§Errors
Returns Err
when the given component
- is empty
- contains characters other than: ascii alphanumeric characters, ‘-’, ‘_’ and ‘.’
- is equal to
.
or..
Sourcepub fn push(
&mut self,
component: impl Into<Cow<'static, str>>,
) -> Result<&mut Self, InvalidS3PathComponent>
pub fn push( &mut self, component: impl Into<Cow<'static, str>>, ) -> Result<&mut Self, InvalidS3PathComponent>
Adds component
to the path after validating it.
§Errors
Returns Err
when the given component
- is empty
- contains characters other than: ascii alphanumeric characters, ‘-’, ‘_’ and ‘.’
- is equal to
.
or..
Sourcepub fn join(
&self,
component: impl Into<Cow<'static, str>>,
) -> Result<Self, InvalidS3PathComponent>
pub fn join( &self, component: impl Into<Cow<'static, str>>, ) -> Result<Self, InvalidS3PathComponent>
Clones this path and pushes [component] onto it.
Leaves this path untouched. Great for quickly creating multiple paths having the same root.
pub fn as_path(&self) -> &S3Path<'_>
Methods from Deref<Target = S3Path<'static>>§
Sourcepub fn join<C: Into<Cow<'static, str>>>(
&self,
component: C,
) -> Result<S3PathBuf, InvalidS3PathComponent>
pub fn join<C: Into<Cow<'static, str>>>( &self, component: C, ) -> Result<S3PathBuf, InvalidS3PathComponent>
Converts to an owned S3PathBuf
and appends component
to it after validating it.
§Errors
Returns Err
when the given component
- is empty
- contains characters other than: ascii alphanumeric characters, ‘-’, ‘_’ and ‘.’
- is equal to
.
or..
Sourcepub fn components(&'i self) -> impl Iterator<Item = &'i str>
pub fn components(&'i self) -> impl Iterator<Item = &'i str>
Returns an iterator over the components of this path.
Sourcepub fn get(&'i self, index: usize) -> Option<&'i str>
pub fn get(&'i self, index: usize) -> Option<&'i str>
Returns the component at the given index, or None if the index is out of bounds.
Sourcepub fn last(&'i self) -> Option<&'i str>
pub fn last(&'i self) -> Option<&'i str>
Returns the last component of this path, or None if the path is empty.
Sourcepub fn parent(&'i self) -> Option<&'i S3Path<'i>>
pub fn parent(&'i self) -> Option<&'i S3Path<'i>>
Returns all but the last component of this path, or None if the path is empty.
Sourcepub fn to_std_path_buf(&self) -> PathBuf
pub fn to_std_path_buf(&self) -> PathBuf
Convert this S3 path to a std::path::PathBuf
, allowing you to use this S3 path as a
system file path.
Our strong guarantee that path components only consist of ascii alphanumeric characters, ‘-’, ‘_’ and ‘.’ and that no path traversal components (‘.’ and ‘..’) are allowed, makes this a safe operation.
Trait Implementations§
Source§impl<'i> PartialEq<&&S3Path<'i>> for S3PathBuf
Allow comparisons between S3Path
and S3PathBuf
.
impl<'i> PartialEq<&&S3Path<'i>> for S3PathBuf
Allow comparisons between S3Path
and S3PathBuf
.