Skip to main content

Origin

Struct Origin 

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

What the host can tell the front end about an invocation, over and above the tokens themselves.

Two of the three capture strategies need something a TokenStream does not carry:

  • The search that finds the invocation in the crate’s own sources needs the crate’s directory — CARGO_MANIFEST_DIR, which Cargo sets for rustc and for rust-analyzer alike — and the name the invocation may be written with, which narrows the candidates.
  • String-literal mode needs the Subspan hook to put a caret inside the literal.

The default is an origin that says nothing: no directory, so no search, and no hook. That is what capture, analyze and expand use — a test building a TokenStream from a string must not depend on the developer’s working directory, or on what happens to be written in the crate around it. The procedural macros pass Origin::new, which is the real thing.

Implementations§

Source§

impl Origin

Source

pub fn unknown() -> Self

An origin that tells capture nothing; see the type documentation.

Source

pub fn new(entry_names: &'static [&'static str]) -> Self

The origin of a real expansion of an entry point that may be written with any of entry_names (&["c89", "c90"] for the two names one entry point has), in the crate Cargo names.

The names carry no ! and no path: an invocation is looked for by its last path segment, so cinrs::c99! is found by "c99".

Source

pub fn with_subspan(self, subspan: Option<Subspan>) -> Self

This origin with a hook that can point inside a string literal; see Subspan.

Source

pub fn in_dir(self, dir: impl Into<PathBuf>) -> Self

This origin with the directory to search set explicitly.

Origin::new reads CARGO_MANIFEST_DIR, which is process-global; a test says which directory it means instead.

Source

pub fn entry_names(&self) -> &'static [&'static str]

The names an invocation of this entry point may be written with.

Source

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

The directory the search walks, when there is one.

Trait Implementations§

Source§

impl Clone for Origin

Source§

fn clone(&self) -> Self

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 Origin

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Origin

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Origin

§

impl !Send for Origin

§

impl !Sync for Origin

§

impl !UnwindSafe for Origin

§

impl Freeze for Origin

§

impl Unpin for Origin

§

impl UnsafeUnpin for Origin

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 = !

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.