fn fromstr(s: &str) -> Result<Self, Self::Err> { let re =…
- User
fn from_str(s: &str) -> Result<Self, Self::Err> { let re = Regex::new(r"s3://(?P[\w_-]+)/(?P.+)").unwrap(); if let Some(captures) = re.captures(s) { if let (Some(bucket), Some(path)) = (captures.name("bucket"), captures.name("path")) { Ok(FileLocation::S3( bucket.as_str().to_owned(), path.as_str().to_owned(), )) } else { Err(FileLocationParseError(s.to_owned())) } } else { Err(FileLocationParseError(s.to_owned())) } }
modify this function to also parse file:// paths. in this case strip the leading file:// and put it in this struct:
pub enum FileLocation { // (file path) (either absolute or relative) Disk(String),
code// (bucket Name, Object key) S3(String, String),} also little cleanup please
- Assistant
Sure! Here's a modified version of the function that also handles paths and performs some cleanup for better readability and maintainability: