pub enum Contents {
Url(Url),
Literal(Vec<u8>),
Path(PathBuf),
}Expand description
The source of an input.
Variants§
Url(Url)
Contents sourced from a URL.
Literal(Vec<u8>)
Contents provided as a literal array of bytes.
Path(PathBuf)
Contents are provided as a path to a file or directory on the host system.
Implementations§
Source§impl Contents
impl Contents
Sourcepub fn url_from_str(url: impl AsRef<str>) -> Result<Self, Error>
pub fn url_from_str(url: impl AsRef<str>) -> Result<Self, Error>
Attempts to create a URL contents from a string slice.
Sourcepub fn one_hot(self) -> Result<(Option<Url>, Option<Vec<u8>>)>
pub fn one_hot(self) -> Result<(Option<Url>, Option<Vec<u8>>)>
Consumes self and one hot encodes the inner contents.
- The first value is the
Urlif the type isContents::Url. Else, the value isNone. - The second value is the literal contents as a
Vec<u8>if the type isContents::LiteralorContents::Path. Else, the value isNone.
Returns an error if the contents are to a path and the file contents could not be read.
Sourcepub async fn fetch(&self, temp_dir: &Path) -> Result<Cow<'_, Path>>
pub async fn fetch(&self, temp_dir: &Path) -> Result<Cow<'_, Path>>
Fetches the contents locally.
If the contents is a path, the path is returned.
If the contents is a literal, they are written to a temporary file.
If the contents is a URL, the file is downloaded to a temporary file.
Returns the path to the contents.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Contents
impl RefUnwindSafe for Contents
impl Send for Contents
impl Sync for Contents
impl Unpin for Contents
impl UnwindSafe for Contents
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