pub enum DataLocation {
Url(Url),
Path(PathBuf),
Blob(Blob),
}Expand description
Re‑exports reader/writer traits, converters, and auxiliary types. A flexible location of data used across I/O code.
§Examples
Creating from strings:
use versatiles_container::DataLocation;
let a = DataLocation::try_from("https://example.org/x.png").unwrap();
let b = DataLocation::try_from("./data/x.png").unwrap();
assert!(matches!(a, DataLocation::Url(_)));
assert!(matches!(b, DataLocation::Path(_)));Resolving against a base:
let base = DataLocation::try_from("/tiles/").unwrap();
let mut tgt = DataLocation::try_from("z/x/y.mvt").unwrap();
tgt.resolve(&base).unwrap();
assert_eq!(tgt.to_string().replace('\\', "/"), "/tiles/z/x/y.mvt");Variants§
Url(Url)
An absolute URL with scheme.
Path(PathBuf)
An absolute file path or a relative path/url.
Blob(Blob)
In-memory blob data.
Implementations§
Source§impl DataLocation
impl DataLocation
Sourcepub fn as_path(&self) -> Result<&Path>
pub fn as_path(&self) -> Result<&Path>
Borrow the underlying filesystem path.
Returns an error if this value is a URL or Blob.
Useful when the caller expects a path-only input and wants a clear error otherwise.
Sourcepub fn to_path_buf(&self) -> Result<PathBuf>
pub fn to_path_buf(&self) -> Result<PathBuf>
Clone the underlying filesystem path as a PathBuf.
Returns an error if this value is a URL or Blob.
Sourcepub fn as_url(&self) -> Result<&Url>
pub fn as_url(&self) -> Result<&Url>
Borrow the underlying URL.
Returns an error if this value is a Path or Blob. Useful when the caller expects a URL-only input and wants a clear error otherwise.
Sourcepub fn resolve(&mut self, base: &DataLocation) -> Result<()>
pub fn resolve(&mut self, base: &DataLocation) -> Result<()>
Resolve this value against base in-place.
Rules:
- If
selfis already a URL, it remains unchanged. - If
baseis a URL andselfis a relative path,selfbecomes a URL viabase.join(). - If both are paths, they are joined and normalized (handling
.and..).
Returns an error only when URL joining fails or inputs are invalid.
Sourcepub fn resolved(&self, base: &DataLocation) -> Result<Self>
pub fn resolved(&self, base: &DataLocation) -> Result<Self>
Return a new DataLocation resolved against base, leaving self unchanged.
This is the non-mutating counterpart of resolve.
Sourcepub fn filename(&self) -> Result<String>
pub fn filename(&self) -> Result<String>
Return the last path segment (e.g., file.tar.gz).
For URLs, the segment is derived from the URL path. For filesystem paths, it is the filename component. Errors if the source has no terminal segment.
Sourcepub fn name(&self) -> Result<String>
pub fn name(&self) -> Result<String>
Return the filename without its last extension.
"/a/file.tar.gz" -> "file.tar", "/a/README" -> "README".
Sourcepub fn extension(&self) -> Result<String>
pub fn extension(&self) -> Result<String>
Return the filename’s last extension (without the dot).
For files, this is the last suffix after a dot (e.g. "/a/file.tar.gz" -> "gz").
For directories (both URLs ending in / and filesystem directories), this returns "directory".
If no extension is present on a non-directory path, this returns an error.
Sourcepub fn parse_with_stdin<R: Read>(input: &str, stdin: R) -> Result<Self>
pub fn parse_with_stdin<R: Read>(input: &str, stdin: R) -> Result<Self>
Parse a DataLocation from a string, reading from stdin if input is "-".
Trait Implementations§
Source§impl Clone for DataLocation
impl Clone for DataLocation
Source§fn clone(&self) -> DataLocation
fn clone(&self) -> DataLocation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DataLocation
impl Debug for DataLocation
Source§impl Display for DataLocation
Display as a plain URL string for Url, as a path using Path::display() for Path,
and as <blob len=N> for in-memory Blob values.
impl Display for DataLocation
Display as a plain URL string for Url, as a path using Path::display() for Path,
and as <blob len=N> for in-memory Blob values.
Source§impl From<&DataLocation> for DataLocation
impl From<&DataLocation> for DataLocation
Source§fn from(u: &DataLocation) -> Self
fn from(u: &DataLocation) -> Self
Source§impl From<&Path> for DataLocation
impl From<&Path> for DataLocation
Source§impl From<&PathBuf> for DataLocation
impl From<&PathBuf> for DataLocation
Source§impl From<Blob> for DataLocation
impl From<Blob> for DataLocation
Source§impl From<PathBuf> for DataLocation
impl From<PathBuf> for DataLocation
Source§impl From<Url> for DataLocation
impl From<Url> for DataLocation
Source§impl PartialEq for DataLocation
impl PartialEq for DataLocation
impl StructuralPartialEq for DataLocation
Source§impl TryFrom<&String> for DataLocation
impl TryFrom<&String> for DataLocation
Source§impl TryFrom<&str> for DataLocation
impl TryFrom<&str> for DataLocation
Source§impl TryFrom<DataLocation> for DataSource
impl TryFrom<DataLocation> for DataSource
Auto Trait Implementations§
impl Freeze for DataLocation
impl RefUnwindSafe for DataLocation
impl Send for DataLocation
impl Sync for DataLocation
impl Unpin for DataLocation
impl UnsafeUnpin for DataLocation
impl UnwindSafe for DataLocation
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§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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.