Skip to main content

SourceRoot

Struct SourceRoot 

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

A source tree root. The root itself may be a link; nothing beneath it is followed.

Implementations§

Source§

impl SourceRoot

Source

pub fn new(root: &Path) -> Self

Opens the root. On Unix the directory is opened here, and every later access goes through that handle, so moving or replacing what the path names afterwards does not move the root; elsewhere the path is resolved to an absolute one here.

Source

pub fn try_clone(&self) -> Self

A second handle on the same root directory.

Source

pub fn path(&self) -> &Path

The path supplied when this root was opened, for display only. It may be relative, moved or replaced; using it to reopen the tree does not preserve this root’s identity. Access files through this root instead.

Source

pub fn exists(&self, path: &str) -> Result<bool, AccessError>

What is at path, not following it, if anything: as the file system finds it by that name, which on one that ignores case, or as on Windows drops trailing dots, can be an entry named otherwise. A path through a file names nothing; a link on the way is an error.

Source

pub fn read( &self, path: &str, limit: u64, ) -> Result<Option<Vec<u8>>, AccessError>

Reads a regular file of at most limit bytes. Ok(None) means the file, or a directory on its way, is missing.

Source

pub fn directory( &self, path: &str, create: bool, ) -> Result<Option<SourceDirectory>, AccessError>

Opens the directory path (the empty path is the root), creating it and its missing parents when create. Ok(None) means it is missing and was not created.

Source

pub fn make_directory(&self, path: &str) -> Result<bool, AccessError>

Makes the directory path in its existing parent. Returns whether this call made it: false when something by that name was already there, which the caller then did not create.

Source

pub fn names( &self, path: &str, limit: usize, ) -> Result<Option<(BTreeSet<String>, usize)>, AccessError>

The UTF-8 names of the entries of the directory path, links included, and how many entries it has, those whose names are not UTF-8 included; None when it is missing. A directory with more than limit entries is an error, AccessError::TooLarge.

Source

pub fn lock(&self) -> Result<SourceLock, AccessError>

Takes the root’s exclusive lock, held until the returned value is dropped. It fails at once with AccessError::Locked if another holder, in this process or another, has it. On Unix it is an advisory flock of the root directory; on Windows the file LOCK_NAME in the root, created afresh, shared with no one and deleted when the lock is released or its process stops, so a file by that name that no one holds is an error. Elsewhere there is no lock and this always succeeds.

Trait Implementations§

Source§

impl Debug for SourceRoot

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.