Skip to main content

TempDryIceFile

Struct TempDryIceFile 

Source
pub struct TempDryIceFile { /* private fields */ }
Expand description

An owned temporary dryice file that evaporates by default.

TempDryIceFile owns a filesystem path created by dryice. The file is removed when cleanup is called, or on drop as a best-effort fallback. Use persist to move the file into a caller-owned location and disable automatic cleanup.

Implementations§

Source§

impl TempDryIceFile

Source

pub fn new() -> Result<Self, DryIceError>

Create a temporary dryice file in the system temporary directory.

§Errors

Returns an error if a temporary file cannot be created.

Source

pub fn new_in<P: AsRef<Path>>(directory: P) -> Result<Self, DryIceError>

Create a temporary dryice file in directory.

The directory must already exist. The file is created with exclusive creation semantics to avoid reusing an existing path.

§Errors

Returns an error if the directory does not exist, if permissions prevent file creation, or if a unique temporary path cannot be created after repeated attempts.

Source

pub fn path(&self) -> &Path

Return the owned temporary file path.

Source

pub fn open(&self) -> Result<File, DryIceError>

Open the owned temporary file for reading and writing.

The returned File is a normal Rust file handle. It can be passed into DryIceWriter, returned by writer.finish(), rewound, and then passed into DryIceReader:

use std::io::{Seek, SeekFrom};

use dryice::{DryIceWriter, SeqRecord, TempDryIceFile};

let temp = TempDryIceFile::new()?;
let file = temp.open()?;
let mut writer = DryIceWriter::builder().inner(file).build();
let record = SeqRecord::new(b"r1".to_vec(), b"ACGT".to_vec(), b"!!!!".to_vec())?;
writer.write_record(&record)?;
let mut file = writer.finish()?;
file.seek(SeekFrom::Start(0))?;
temp.cleanup()?;
§Errors

Returns an error if the temporary file cannot be opened.

Source

pub fn cleanup(self) -> Result<(), DryIceError>

Remove the temporary file now.

Missing files are treated as already cleaned up. If the file has already been persisted, cleanup is a no-op because dryice no longer owns the file lifecycle.

§Errors

Returns an error if removing the temporary file fails for reasons other than the file already being absent.

Source

pub fn persist<P: AsRef<Path>>( &mut self, path: P, ) -> Result<PathBuf, DryIceError>

Move the temporary file into a caller-owned path.

After a successful persist, dryice no longer owns the file lifecycle and will not remove the destination on drop. The destination must not already exist.

§Errors

Returns an error if path already exists or if the temporary file cannot be renamed to path.

Trait Implementations§

Source§

impl Drop for TempDryIceFile

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V