pub struct XTrace { /* private fields */ }Expand description
Collection of temporary string buffers that accumulate expanded strings
See the module documentation for details.
An XTrace contains four string buffers that accumulate each of the
following:
- Command words (command name and arguments)
- Assignments
- Redirections
- Here-document contents
The finish function creates the final string to be
printed.
Implementations§
Source§impl XTrace
impl XTrace
Sourcepub fn from_options(options: &OptionSet) -> Option<Self>
pub fn from_options(options: &OptionSet) -> Option<Self>
Creates a new trace buffer if the xtrace option is on.
If the option is off, this function returns None.
Sourcepub fn words(&mut self) -> &mut (impl Write + use<>)
pub fn words(&mut self) -> &mut (impl Write + use<>)
Returns a reference to the words buffer.
The words buffer is for tracing command words. When writing to the buffer, the content should end with a space.
Sourcepub fn assigns(&mut self) -> &mut (impl Write + use<>)
pub fn assigns(&mut self) -> &mut (impl Write + use<>)
Returns a reference to the assignments buffer.
The assignments buffer is for tracing assignments. When writing to the buffer, the content should end with a space.
Sourcepub fn redirs(&mut self) -> &mut (impl Write + use<>)
pub fn redirs(&mut self) -> &mut (impl Write + use<>)
Returns a reference to the redirections buffer.
The redirections buffer is for tracing redirections. When writing to the buffer, the content should end with a space.
You should not write the contents of here-documents to this buffer.
See also here_doc_contents.
Sourcepub fn here_doc_contents(&mut self) -> &mut (impl Write + use<>)
pub fn here_doc_contents(&mut self) -> &mut (impl Write + use<>)
Returns a reference to the here-document contents buffer.
You should write the contents of here-documents you wrote to the redirections buffer.
Sourcepub async fn finish(&self, env: &mut Env) -> String
pub async fn finish(&self, env: &mut Env) -> String
Constructs the final trace to be printed to stderr.
If all the buffers are empty, the result is empty. Otherwise, the result is the concatenation of the following:
- The expansion of
$PS4 - The concatenation of the
assigns,words, andredirsbuffers with trailing spaces trimmed and a newline appended - The
here_doc_contentsbuffer
If $PS4 fails to expand, this function prints an error message and
uses the variable value intact.
If this function is called while $PS4 is being expanded inside this
function, the expansion of $PS4 is skipped and an empty string is
returned. This prevents infinite recursion when $PS4 contains a
command substitution that causes XTrace::finish to be called again.
Trait Implementations§
impl Eq for XTrace
impl StructuralPartialEq for XTrace
Auto Trait Implementations§
impl Freeze for XTrace
impl RefUnwindSafe for XTrace
impl Send for XTrace
impl Sync for XTrace
impl Unpin for XTrace
impl UnwindSafe for XTrace
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more