| 435 | /// Creates a file URL from a potentially relative filesystem path |
| 436 | #[cfg(not(target_arch = "wasm32"))] |
| 437 | fn url_from_filesystem_path(s: &str) -> Option<Url> { |
| 438 | let path = std::path::Path::new(s); |
| 439 | let is_dir = match path.exists() { |
| 440 | true => path.is_dir(), |
| 441 | // Fallback to inferring from trailing separator |
| 442 | false => std::path::is_separator(s.chars().last()?), |
| 443 | }; |
| 444 | |
| 445 | let from_absolute_path = |p| { |
| 446 | let first = match is_dir { |
| 447 | true => Url::from_directory_path(p).ok(), |
| 448 | false => Url::from_file_path(p).ok(), |
| 449 | }?; |
| 450 | |
| 451 | // By default from_*_path preserve relative path segments |
| 452 | // We therefore parse the URL again to resolve these |
| 453 | Url::parse(first.as_str()).ok() |
| 454 | }; |
| 455 | |
| 456 | if path.is_absolute() { |
| 457 | return from_absolute_path(path); |
| 458 | } |
| 459 | |
| 460 | let absolute = std::env::current_dir().ok()?.join(path); |
| 461 | from_absolute_path(&absolute) |
| 462 | } |
| 463 | |
| 464 | impl AsRef<str> for ListingTableUrl { |
| 465 | fn as_ref(&self) -> &str { |