Skip to main content

RdDocument

Struct RdDocument 

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

A complete parsed Rd document.

nodes are the top-level children of the parsed Rd object: a mix of section-tagged nodes (\name, \title, \description, …) and the whitespace TEXT leaves R’s parser leaves between them. Nothing is filtered out at this layer – see the crate-level documentation for the losslessness rationale.

Implementations§

Source§

impl RdDocument

Source

pub fn new(nodes: Vec<RdNode>) -> Self

Source

pub fn nodes(&self) -> &[RdNode]

Source

pub fn into_nodes(self) -> Vec<RdNode>

Source§

impl RdDocument

Source

pub fn title(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \title{...}’s children, if any. See Self::inspect_title for diagnostics.

“First-wins”: if \title appears more than once at the top level (malformed input), only the first occurrence is returned. Only RdNode::Tagged top-level nodes are considered – see the module-level documentation for why a top-level RdNode::Raw node whose tag string happens to be "\\title" is not matched.

Source

pub fn description(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \description{...}’s children, if any. See Self::inspect_description for diagnostics.

Same first-wins-on-duplicates and Tagged-only semantics as RdDocument::title.

Source

pub fn usage(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \usage{...}’s children, if any. See Self::inspect_usage for diagnostics.

Same first-wins-on-duplicates and Tagged-only semantics as RdDocument::title.

Source

pub fn value(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \value{...}’s children, if any. See Self::inspect_value for diagnostics.

Same first-wins-on-duplicates and Tagged-only semantics as RdDocument::title.

Source

pub fn name(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \name{...}’s children, if any. See Self::inspect_name for diagnostics. First-wins on duplicates.

Source

pub fn details(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \details{...}’s children, if any. See Self::inspect_details for diagnostics. First-wins on duplicates.

Source

pub fn note(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \note{...}’s children, if any. See Self::inspect_note for diagnostics. First-wins on duplicates.

Source

pub fn author(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \author{...}’s children, if any. See Self::inspect_author for diagnostics. First-wins on duplicates.

Source

pub fn references(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \references{...}’s children, if any. See Self::inspect_references for diagnostics. First-wins on duplicates.

Source

pub fn see_also(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \seealso{...}’s children, if any. See Self::inspect_see_also for diagnostics. First-wins on duplicates.

Source

pub fn examples(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \examples{...}’s children, if any. See Self::inspect_examples for diagnostics. First-wins on duplicates.

Source

pub fn format(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \format{...}’s children, if any. See Self::inspect_format for diagnostics. First-wins on duplicates.

Source

pub fn source(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \source{...}’s children, if any. See Self::inspect_source for diagnostics. First-wins on duplicates.

Source

pub fn encoding(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \encoding{...}’s children, if any. See Self::inspect_encoding for diagnostics. First-wins on duplicates.

Source

pub fn doc_type(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \docType{...}’s children, if any. See Self::inspect_doc_type for diagnostics. First-wins on duplicates.

Source

pub fn rd_version(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \Rdversion{...}’s children, if any. See Self::inspect_rd_version for diagnostics. First-wins on duplicates.

Source

pub fn synopsis(&self) -> Option<&[RdNode]>

Lossy: returns the first top-level \synopsis{...}’s children, if any. See Self::inspect_synopsis for diagnostics. First-wins on duplicates.

Source

pub fn aliases(&self) -> impl Iterator<Item = String> + '_

Lossy: iterates the current topic’s \alias{...} declarations, in source order, yielding each alias’s text_contents (no splitting, no trimming – an alias with empty children yields an empty string).

This reads the topic’s own \alias markup, i.e. the alias names this specific Rd document declares for itself. It is unrelated to a package-wide help/aliases.rds index (as read by e.g. rd-helpdb’s PackageHelpDb::aliases/resolve_alias), which maps every alias in a package to the topic file that documents it.

Only top-level RdNode::Tagged nodes are considered – see the module-level documentation for why a top-level RdNode::Raw node whose tag string happens to be "\\alias" is not matched.

Source

pub fn keywords(&self) -> impl Iterator<Item = String> + '_

Lossy: iterates top-level \keyword{...} declarations in source order.

Source

pub fn concepts(&self) -> impl Iterator<Item = String> + '_

Lossy: iterates top-level \concept{...} declarations in source order.

Source

pub fn sections(&self) -> impl Iterator<Item = RdSection<'_>>

Lossy: iterates the document’s custom \section{title}{body} nodes, in source order.

This is distinct from the standard, fixed-vocabulary sections (\description, \value, \details, …), which are read individually (see RdDocument::title, RdDocument::description, etc.). It only recognizes custom \section{...}{...} markup (RdTag::Section).

A top-level node is recognized as a section only when it is a Tagged node with RdTag::Section, no option, and exactly two RdNode::Group children (the title/body positional- argument groups the \section macro lowers to). Anything else is silently skipped rather than erroring. For nested \subsection traversal, see Self::section_tree.

Source

pub fn arguments(&self) -> impl Iterator<Item = RdArgument<'_>>

Lossy: iterates the \item{name}{description} entries of the first top-level \arguments{...} node, in source order.

Only the FIRST top-level Tagged node with RdTag::Arguments node is considered (first-wins on duplicates, like RdDocument::title); its DIRECT children are then scanned – nested \arguments are not (there is no such thing in valid Rd, but this function makes no attempt to look for one either way).

A direct child yields an RdArgument only when it matches a Tagged node with RdTag::Item, no option, and the given children where children has exactly two RdNode::Group children (the name/description positional-argument groups the two-argument form of \item lowers to). Everything else is silently skipped: the whitespace TEXT leaves between \items, an \item[label] with an option (the zero/one-argument \itemize/\enumerate form, not the two-argument \arguments/\describe form), an \item with the wrong number of children, and any other non-\item markup. This is a total function – it never errors, it just yields fewer items than the source \arguments block might structurally contain.

If \arguments itself isn’t found as a top-level Tagged node (see the module-level documentation on why Raw is never interpreted), this yields no items.

Source

pub fn inspect_title(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::title accessor.

Source

pub fn inspect_description(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::description accessor.

Source

pub fn inspect_usage(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::usage accessor.

Source

pub fn inspect_value(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::value accessor.

Source

pub fn inspect_name(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::name accessor.

Source

pub fn inspect_details(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::details accessor.

Source

pub fn inspect_note(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::note accessor.

Source

pub fn inspect_author(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::author accessor.

Source

pub fn inspect_references(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::references accessor.

Source

pub fn inspect_see_also(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::see_also accessor.

Source

pub fn inspect_examples(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::examples accessor.

Source

pub fn inspect_format(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::format accessor.

Source

pub fn inspect_source(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::source accessor.

Source

pub fn inspect_encoding(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::encoding accessor.

Source

pub fn inspect_doc_type(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::doc_type accessor.

Source

pub fn inspect_rd_version(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::rd_version accessor.

Source

pub fn inspect_synopsis(&self) -> Result<Option<&[RdNode]>, RdShapeError>

Strict counterpart to the lossy Self::synopsis accessor.

Source

pub fn inspect_aliases( &self, ) -> impl Iterator<Item = Result<RdAlias<'_>, RdShapeError>> + '_

Strict counterpart to the lossy Self::aliases accessor.

Source

pub fn inspect_keywords( &self, ) -> impl Iterator<Item = Result<RdKeyword<'_>, RdShapeError>> + '_

Strict counterpart to the lossy Self::keywords accessor.

Source

pub fn inspect_concepts( &self, ) -> impl Iterator<Item = Result<RdConcept<'_>, RdShapeError>> + '_

Strict counterpart to the lossy Self::concepts accessor.

Source

pub fn section_tree(&self) -> impl Iterator<Item = RdSectionVisit<'_>>

Lossy depth-first preorder traversal of recognized top-level \section nodes and recognized nested \subsection nodes.

Malformed candidates and their descendants are skipped. An orphan top-level \subsection is outside this view; source-parser diagnostics own that condition. See Self::sections for the top-level-only view.

Source

pub fn inspect_section_tree( &self, ) -> impl Iterator<Item = Result<RdSectionVisit<'_>, RdShapeError>>

Strict depth-first preorder traversal of recognized top-level \section nodes and recognized nested \subsection nodes.

Each malformed candidate yields one error and its descendants are not traversed. An orphan top-level \subsection is outside this view; source-parser diagnostics own that condition. See Self::sections for the top-level-only view.

Source

pub fn inspect_sections( &self, ) -> impl Iterator<Item = Result<RdSection<'_>, RdShapeError>> + '_

Strict counterpart to the lossy Self::sections accessor.

Source

pub fn inspect_arguments( &self, ) -> Result<impl Iterator<Item = Result<RdArgument<'_>, RdShapeError>> + '_, RdShapeError>

Strict counterpart to the lossy Self::arguments accessor.

Source§

impl RdDocument

Source

pub fn inspect_dynamic_markup(&self) -> RdDynamicMarkupIter<'_>

Returns a depth-first pre-order resolver for \\RdOpts and \\Sexpr.

The resolver deliberately mirrors R’s observable processRdSexprs semantics: a single options state is folded in document order. Conditional markup (\\if/\\ifelse) is not branch-selected here; therefore an \\RdOpts in an arm that a renderer would not select still affects later \\Sexpr resolution, matching R’s behavior.

Source§

impl RdDocument

Source

pub fn generation_header(&self) -> Option<RdGenerationHeader<'_>>

Returns the recognized generation header in the leading top-level region.

The view scans only leading comments interleaved with whitespace text. It is lossy: near-miss text is not recognized, and there is deliberately no inspection variant because this view has no structural error state.

Source§

impl RdDocument

Source§

impl RdDocument

Trait Implementations§

Source§

impl Clone for RdDocument

Source§

fn clone(&self) -> RdDocument

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 RdDocument

Source§

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

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

impl<'de> Deserialize<'de> for RdDocument

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Vec<RdNode>> for RdDocument

Source§

fn from(nodes: Vec<RdNode>) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for RdDocument

Source§

type Item = RdNode

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<RdNode>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a RdDocument

Source§

type Item = &'a RdNode

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, RdNode>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for RdDocument

Source§

fn eq(&self, other: &RdDocument) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for RdDocument

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RdDocument

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.