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 forrustcand forrust-analyzeralike — and the name the invocation may be written with, which narrows the candidates. - String-literal mode needs the
Subspanhook 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
impl Origin
Sourcepub fn unknown() -> Self
pub fn unknown() -> Self
An origin that tells capture nothing; see the type documentation.
Sourcepub fn new(entry_names: &'static [&'static str]) -> Self
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".
Sourcepub fn with_subspan(self, subspan: Option<Subspan>) -> Self
pub fn with_subspan(self, subspan: Option<Subspan>) -> Self
This origin with a hook that can point inside a string literal; see
Subspan.
Sourcepub fn in_dir(self, dir: impl Into<PathBuf>) -> Self
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.
Sourcepub fn entry_names(&self) -> &'static [&'static str]
pub fn entry_names(&self) -> &'static [&'static str]
The names an invocation of this entry point may be written with.