Skip to main content

Source

Struct Source 

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

Source::open on a file retains the primary bytes and permits constrained acquisition of referenced files beneath the file’s canonical containing directory; Source::with_acquisition_root widens that root at construction, and never from a parser. Source::from_bytes grants no filesystem access; referenced content reaches an in-memory source only through Source::with_named_buffer.

Implementations§

Source§

impl Source

Source

pub fn open(path: impl Into<PathBuf>) -> Result<Self, Error>

Acquire a file eagerly or a directory lazily.

Source

pub fn from_bytes( name: impl Into<String>, bytes: impl Into<Arc<[u8]>>, ) -> Result<Self, Error>

Retain a caller-owned binary or text buffer. An Arc<[u8]> argument is retained without copying; a Vec<u8> is copied once into the shared buffer, since Arc<[u8]> needs its own allocation.

Source

pub fn with_named_buffer( self, name: impl Into<String>, bytes: impl Into<Arc<[u8]>>, ) -> Result<Self, Error>

Supply one referenced buffer to an in-memory source under the relative name a format uses to refer to it. This is the only way referenced content reaches a source built by Source::from_bytes; such a source never touches the filesystem.

Source

pub fn with_acquisition_root( self, root: impl Into<PathBuf>, ) -> Result<Self, Error>

Widen the acquisition root of a file source to a directory that contains the file, selected while constructing the source. A parser can never widen the root.

Source

pub fn with_format(self, format: FormatId) -> Self

Select one parser explicitly while retaining the same source owner.

Source

pub fn name(&self) -> &str

Source

pub const fn format(&self) -> Option<&FormatId>

Source

pub fn is_directory(&self) -> bool

Source

pub fn primary_buffer(&self) -> Result<SourceBuffer, Error>

Borrow the sole primary buffer of a file or memory source.

Source

pub fn buffer(&self, name: &ArtifactPath) -> Result<SourceBuffer, Error>

Acquire and retain one file of a directory source by its root relative name.

Source

pub fn root_buffer(&self, name: &str) -> Result<SourceBuffer, Error>

Acquire and retain one file beneath the acquisition root by its root relative name, for a parser that resolves referenced names itself and hands over the resolved result. An in-memory source consults the buffers the caller supplied.

Source

pub fn selected_acquisition_root(&self) -> Option<&Path>

The canonical root selected with Source::with_acquisition_root, None when the root defaulted to the containing directory or the source is not file backed. Read-only context for a parser’s own resolution and refusal wording; acquisition itself always goes through this source.

Source

pub fn referenced_buffer( &self, referrer: &SourceBuffer, name: &str, ) -> Result<SourceBuffer, Error>

Acquire and retain one file referenced by referrer, resolved against the referring file’s directory and confined beneath the acquisition root. An in-memory source resolves the same name against the buffers the caller supplied and never touches the filesystem.

Source

pub fn entry_names(&self) -> Result<Vec<ArtifactPath>, Error>

The root relative file names of a directory source, in sorted order, so a directory format can report files outside its profile without touching the filesystem itself. Symbolic links are listed by name and refused if acquired. The listing is bounded by the referenced file budget; a directory holding more entries is refused.

Source

pub fn acquired_buffers(&self) -> Vec<SourceBuffer>

Buffers already retained by this source, in deterministic name order.

Trait Implementations§

Source§

impl Clone for Source

Source§

fn clone(&self) -> Source

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Source

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.