/// Parses the URI and returns a variant of the Uri enum for the appropriate storage backend based
/// on scheme.
Parses the URI and returns a variant of the Uri enum for the appropriate storage backend based
on scheme.
Parses the URI and returns a variant of the Uri enum for the appropriate storage backend based on scheme .
pub fn parse_uri<'a>(path: &'a str) -> Result<Uri<'a>, UriError> {
    let parts: Vec<&'a str> = path.split("://").collect();
    if parts.len() == 1 {
        return Ok(Uri::LocalPath(parts[0]));
    }
    match parts[0] {
        "s3" => {
            cfg_if::cfg_if! {
                if #[cfg(any(feature = "s3", feature = "s3-rustls"))] {
                    let mut path_parts = parts[1].splitn(2, '/');
                    let bucket = match path_parts.next() {
                        Some(x) => x,
                        None => {
                            return Err(UriError::MissingObjectBucket);
                        }
                    };
                    let key = match path_parts.next() {
                        Some(x) => x,
                        None => {
                            return Err(UriError::MissingObjectKey);
                        }
                    };
                    Ok(Uri::S3Object(s3::S3Object { bucket, key }))
                } else {
                    Err(UriError::InvalidScheme(String::from(parts[0])))
                }
            }
        }
        "file" => Ok(Uri::LocalPath(parts[1])),
        "abfss" => {
            cfg_if::cfg_if! {
                if #[cfg(feature = "azure")] {
                    // URI scheme: abfs[s]://<file_system>@<account_name>.dfs.core.windows.net/<path>/<file_name>
                    let mut parts = parts[1].splitn(2, '@');
                    let file_system = parts.next().ok_or(UriError::MissingObjectFileSystem)?;
                    let mut parts = parts.next().map(|x| x.splitn(2, '.')).ok_or(UriError::MissingObjectAccountAndPath)?;
                    let account_name = parts.next().ok_or(UriError::MissingObjectAccountName)?;
                    let mut paths = parts.next().map(|x| x.splitn(2, '/')).ok_or(UriError::MissingObjectPath)?;
                    // assume root when uri ends without `/`
                    let path = paths.nth(1).unwrap_or("");
                    Ok(Uri::AdlsGen2Object(azure::AdlsGen2Object { account_name, file_system, path }))
                } else {
                    Err(UriError::InvalidScheme(String::from(parts[0])))
                }
            }
        }
        _ => Err(UriError::InvalidScheme(String::from(parts[0]))),
    }
}
pub fn parse_uri < ' a > ( path : & ' a str ) -> Result < Uri < ' a > , UriError > { let parts : Vec < & ' a str > = path . split ( " " ) . collect ( ) ; if parts . len ( ) == 1 { return Ok ( Uri :: LocalPath ( parts [ 0 ] ) ) ; } match parts [ 0 ] { " " => { cfg_if :: cfg_if ! { if [ cfg ( any ( feature " " feature " " ) ) ] { let mut path_parts parts [ 1 ] splitn ( 2 '/' ) let bucket match path_parts next ( ) { Some ( x ) x None { return Err ( UriError MissingObjectBucket ) } } let key match path_parts next ( ) { Some ( x ) x None { return Err ( UriError MissingObjectKey ) } } Ok ( Uri S3Object ( s3 S3Object { bucket key } ) ) } else { Err ( UriError InvalidScheme ( String from ( parts [ 0 ] ) ) ) } } } " " => Ok ( Uri :: LocalPath ( parts [ 1 ] ) ) , " " => { cfg_if :: cfg_if ! { if [ cfg ( feature " " ) ] { // URI scheme: abfs[s]://<file_system>@<account_name>.dfs.core.windows.net/<path>/<file_name> let mut parts parts [ 1 ] splitn ( 2 '@' ) let file_system parts next ( ) ok_or ( UriError MissingObjectFileSystem ) let mut parts parts next ( ) map ( x x splitn ( 2 '.' ) ) ok_or ( UriError MissingObjectAccountAndPath ) let account_name parts next ( ) ok_or ( UriError MissingObjectAccountName ) let mut paths parts next ( ) map ( x x splitn ( 2 '/' ) ) ok_or ( UriError MissingObjectPath ) // assume root when uri ends without `/` let path paths nth ( 1 ) unwrap_or ( " " ) Ok ( Uri AdlsGen2Object ( azure AdlsGen2Object { account_name file_system path } ) ) } else { Err ( UriError InvalidScheme ( String from ( parts [ 0 ] ) ) ) } } } _ => Err ( UriError :: InvalidScheme ( String :: from ( parts [ 0 ] ) ) ) , } }
Parses the URI and returns a variant of the Uri enum for the appropriate storage backend based
on scheme.
Parses the URI and returns a variant of the Uri enum for the appropriate storage backend based on scheme .
path
&'a str