pub struct File { /* private fields */ }
Expand description
Resource representing file system file
Implementations§
Source§impl File
impl File
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Self, Box<dyn Error>>
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, Box<dyn Error>>
Create new File pointing to absolute file system path
Sourcepub fn created(self) -> Self
pub fn created(self) -> Self
Creates the file using create
and returns itself or stops the build with
informative error message.
Sourcepub fn create(&self) -> File
pub fn create(&self) -> File
Creates the file using create_result
or stops the build with
informative error message.
Sourcepub fn create_result(&self) -> Result<File>
pub fn create_result(&self) -> Result<File>
Creates (or truncates) the file and any missing directories on it’s path in write only mode.
Sourcepub fn linked_from_inside(self, dir: &Dir) -> Self
pub fn linked_from_inside(self, dir: &Dir) -> Self
Creating a link to this file from another directory with this file’s name returning self or stopping the build with informative error message.
If the directory already contains an entry with this name, linking fails.
Sourcepub fn link_from_inside(&self, dir: &Dir)
pub fn link_from_inside(&self, dir: &Dir)
Creating a link to this file from another directory with this file’s name or stops the build with informative error message.
If the directory already contains an entry with this name, linking fails.
Sourcepub fn link_from_inside_result(&self, dir: &Dir, force: bool) -> Result<()>
pub fn link_from_inside_result(&self, dir: &Dir, force: bool) -> Result<()>
Creating a link to this file from another directory with this file’s name.
If the directory already contains a file or directory by this name, linking fails.
To allow overwriting existing link with different target set force
to true
or linking to
this file will also fail.
Sourcepub fn linked_to(self, to: &File) -> Self
pub fn linked_to(self, to: &File) -> Self
Create a symbolic link at this file path to given target file to
creating any needed
directories in the process returning self or stops the build with informative error message.
If a file or directory by that name already exists, linking will fail.
Sourcepub fn link_to(&self, to: &File)
pub fn link_to(&self, to: &File)
Create a symbolic link at this file path to given target file to
creating any needed
directories in the process or stops the build with informative error message.
If a file or directory by that name already exists, linking will fail.
Sourcepub fn link_to_result(&self, to: &File, force: bool) -> Result<()>
pub fn link_to_result(&self, to: &File, force: bool) -> Result<()>
Create a symbolic link at this file path to given target file to
creating any needed
directories in the process.
If a file or directory by that name already exists, linking will fail.
To allow overwriting existing link to a different file set force
to true
or linking to
a different file will also fail.
Sourcepub fn metadata(&self) -> Metadata
pub fn metadata(&self) -> Metadata
Opens file’s metadata using metadata_result
or stops the build
with informative error message.
Sourcepub fn metadata_result(&self) -> Result<Metadata>
pub fn metadata_result(&self) -> Result<Metadata>
Opens file metadata
Sourcepub fn open(&self) -> File
pub fn open(&self) -> File
Opens the file using open_result
or stops the build with
informative error message
Sourcepub fn open_result(&self) -> Result<File>
pub fn open_result(&self) -> Result<File>
Opens the file in read only mode
Sourcepub fn rewrite<P: AsRef<[u8]>>(&self, bytes: P)
pub fn rewrite<P: AsRef<[u8]>>(&self, bytes: P)
Writes the entire content to the file using rewrite_result
or
stops the build with informative error message
Sourcepub fn rewrite_result<P: AsRef<[u8]>>(&self, bytes: P) -> Result<()>
pub fn rewrite_result<P: AsRef<[u8]>>(&self, bytes: P) -> Result<()>
Writes the entire content to the file if it is different then the current one creating the file if needed.
Sourcepub fn touched(self) -> Self
pub fn touched(self) -> Self
Touches the file using touch
and returns itself or stops the build with
informative error message
Sourcepub fn touch(&self)
pub fn touch(&self)
Touches the file using touch
and returns itself or stops the build with
informative error message.
Sourcepub fn touch_result(&self) -> Result<()>
pub fn touch_result(&self) -> Result<()>
Touches the file by updating it’s modification time or creating an empty one if it does not exists yet including any needed directories.