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 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 bookmark(&self, read_only: bool) -> Result<Vec<u8>>
pub fn bookmark(&self, read_only: bool) -> Result<Vec<u8>>
Persistable macOS security-scoped bookmark for a file the user has authorized.
Store the opaque bytes in app-private storage, not the path. Other platforms return
Unsupported. read_only prevents a bookmark from requesting write access.
Sourcepub fn resolve_bookmark(bytes: &[u8]) -> Result<FileAccess>
pub fn resolve_bookmark(bytes: &[u8]) -> Result<FileAccess>
Resolve a saved macOS bookmark and hold its security scope until the returned guard is dropped. Keep the guard alive across all I/O, including asynchronous operations.
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 async fn read_limited(&self, limit: usize) -> Result<Vec<u8>>
pub async fn read_limited(&self, limit: usize) -> Result<Vec<u8>>
Read at most limit bytes without blocking the UI. Native reads run on a worker;
browser-picked bytes are already in memory. Oversized input returns InvalidData.
Apple security-scoped access is held for the read and released on every exit path.
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,
impl<T> ErasedDestructor for Twhere
T: 'static,
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