pub enum Source<'a> {
Path(PathBuf),
Url(SourceUrl<'a>),
Name(&'a str),
}Expand description
The source location for media content (images, audio, video).
Source is an enum, not a struct with a path field. Use pattern matching
to extract the underlying value:
§Accessing the Source
fn get_path_string(source: &Source) -> String {
match source {
Source::Path(path) => path.display().to_string(),
Source::Url(url) => url.to_string(),
Source::Name(name) => (*name).to_string(),
}
}Or use the Display implementation for simple string conversion:
let source_str = source.to_string();§Variants
Path(PathBuf)- Local filesystem path (e.g.,images/photo.png)Url(url::Url)- Remote URL (e.g.,https://example.com/image.png)Name(&str)- Simple identifier (e.g., icon names likeheart,github)
Variants§
Path(PathBuf)
A filesystem path (relative or absolute).
Url(SourceUrl<'a>)
A URL (http, https, ftp, etc.).
Name(&'a str)
A simple name (used for icon names, menu targets, etc.).
Implementations§
Source§impl Source<'_>
impl Source<'_>
Sourcepub fn get_filename(&self) -> Option<&str>
pub fn get_filename(&self) -> Option<&str>
Get the filename from the source.
For paths, this returns the file name component. For URLs, it returns the last path segment. For names, it returns the name itself.
Source§impl<'a> Source<'a>
impl<'a> Source<'a>
Sourcepub fn from_str_borrowed(value: &'a str) -> Result<Self, Error>
pub fn from_str_borrowed(value: &'a str) -> Result<Self, Error>
Construct a Source from a borrowed string, classifying it as either a
URL or a filesystem path based on its scheme.
§Errors
Returns Error::Parse when value looks like a URL (starts with a
recognised scheme) but fails URL parsing.
Trait Implementations§
impl<'a> StructuralPartialEq for Source<'a>
Auto Trait Implementations§
impl<'a> Freeze for Source<'a>
impl<'a> RefUnwindSafe for Source<'a>
impl<'a> Send for Source<'a>
impl<'a> Sync for Source<'a>
impl<'a> Unpin for Source<'a>
impl<'a> UnsafeUnpin for Source<'a>
impl<'a> UnwindSafe for Source<'a>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more