pub struct FileUrl(/* private fields */);Expand description
A cross-platform handle to a file the user chose in a native open/save picker.
Internally a single locator string. On desktop and iOS it is an absolute filesystem
path; on Android it may be a content:// URI, since the Storage Access Framework does not
expose real filesystem paths. That is why Day uses a bespoke type rather than
std::path::PathBuf (which cannot represent a content:// URI) or a bare String (no
type-safety / helpers): a FileUrl is the lossless union with ergonomic accessors.
Files returned from open_file are always readable via FileUrl::read_to_string /
FileUrl::read — backends copy a picked file into app storage first where the platform
requires it, so the local path “just works” everywhere.
Implementations§
Source§impl FileUrl
impl FileUrl
Sourcepub fn new(locator: impl Into<String>) -> Self
pub fn new(locator: impl Into<String>) -> Self
Wrap a locator string (a filesystem path or a URI). Usually produced by the pickers.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
The raw locator: a filesystem path, or a content://-style URI on Android.
Sourcepub fn local_path(&self) -> Option<PathBuf>
pub fn local_path(&self) -> Option<PathBuf>
The locator as a filesystem path — Some for local paths (and file:// URLs), None
for opaque URIs such as Android’s content://.
Sourcepub fn file_name(&self) -> Option<String>
pub fn file_name(&self) -> Option<String>
The last path component, for display (e.g. notes.txt). Best-effort for opaque URIs.
Sourcepub fn read(&self) -> Result<Vec<u8>>
pub fn read(&self) -> Result<Vec<u8>>
Read the file’s bytes. Local paths only; opaque URIs return an Unsupported error.
Sourcepub fn read_to_string(&self) -> Result<String>
pub fn read_to_string(&self) -> Result<String>
Read the file as UTF-8 text.
Trait Implementations§
impl Eq for FileUrl
impl StructuralPartialEq for FileUrl
Auto Trait Implementations§
impl Freeze for FileUrl
impl RefUnwindSafe for FileUrl
impl Send for FileUrl
impl Sync for FileUrl
impl Unpin for FileUrl
impl UnsafeUnpin for FileUrl
impl UnwindSafe for FileUrl
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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> 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 more