Skip to main content

RenderView

Trait RenderView 

Source
pub trait RenderView: Sized {
Show 16 methods // Provided methods fn reserved_keywords() -> &'static HashSet<String> { ... } fn is_reserved_keyword(id: &str) -> bool { ... } fn should_escape(id: &str) -> bool { ... } fn escape(id: &str) -> String { ... } fn render_unnamed_path_segment_payload( &self, unnamed: UnnamedPathSegmentPayload, ) -> Symbol { ... } fn render_path_segment_payload(&self, payload: PathSegmentPayload) -> Symbol { ... } fn render_path_segment(&self, seg: &PathSegment) -> Vec<String> { ... } fn render_suffix(&self, suffix: &ReservedSuffix) -> String { ... } fn module(&self, view: &View) -> Vec<String> { ... } fn relativize_module_path<'a>( &self, module_path: &'a [PathSegment], ) -> &'a [PathSegment] { ... } fn render(&self, view: &View) -> Rendered { ... } fn separator(&self) -> &str { ... } fn rendered_to_strings( &self, rendered: Rendered, ) -> impl Iterator<Item = String> { ... } fn rendered_to_string(&self, rendered: Rendered) -> String { ... } fn render_string(&self, view: &View) -> String { ... } fn render_strings(&self, view: &View) -> impl Iterator<Item = String> { ... }
}
Expand description

A helper trait to render a View (a typed list of path segments) into strings.

Rendering is split into two parts:

  • module path: the crate + module prefix,
  • relative path: the remaining (non-module) segments, and both may contain hierarchical sub-segments (e.g. Foo::MyVariant::field).

Implementors can:

  • override how unnamed segments (e.g. impl, anon const) are displayed,
  • override how each segment is rendered,
  • customize the separator (defaults to "::"),
  • render to either a structured Rendered or a single flat String.

§Terminology

A path segment can be:

§Hierarchical segments

Some segments are actually small trees (e.g., field → constructor → type). RenderView::render_path_segment returns all display atoms for such a segment, so callers can flatten or join as needed.

Provided Methods§

Source

fn reserved_keywords() -> &'static HashSet<String>

List of reserved keywords that will be escaped when rendering

Source

fn is_reserved_keyword(id: &str) -> bool

Check if a string is a reserved keyword that needs escaping

Source

fn should_escape(id: &str) -> bool

Check if a string needs escaping

Source

fn escape(id: &str) -> String

Escape a string if it needs escaping according to Self::should_escape

Source

fn render_unnamed_path_segment_payload( &self, unnamed: UnnamedPathSegmentPayload, ) -> Symbol

Converts an unnamed path segment payload into a printable Symbol.

Unnamed segments include impl, anon const, inline const, foreign mod, global_asm, use, opaque, and closure. By default, these map to their capitalized identifier (e.g., Impl, AnonConst, …).

Override this method to customize how unnamed items appear in output.

Source

fn render_path_segment_payload(&self, payload: PathSegmentPayload) -> Symbol

Converts a full PathSegmentPayload (named or unnamed) into a printable Symbol.

Named payloads return their Symbol unchanged. Unnamed payloads are delegated to [render_unnamed_path_segment_payload].

Source

fn render_path_segment(&self, seg: &PathSegment) -> Vec<String>

Renders a single PathSegment into a vector of display atoms.

Most segments render to a single atom (e.g., "Foo"). Hierarchical segments (like a field) render to multiple atoms representing their parent chain (e.g., ["Foo", "MyVariant", "my_field"]). Disambiguators (see PathSegment::disambiguator) are suffixed as _N when N > 0.

The resulting atoms are suitable for joining with separator, or for further grouping into module vs. relative path.

Source

fn render_suffix(&self, suffix: &ReservedSuffix) -> String

Renders the optional suffix

Source

fn module(&self, view: &View) -> Vec<String>

Renders just the module path (crate + modules) of a View, as a list of atoms.

This is a convenience wrapper around render that returns only the module component.

Source

fn relativize_module_path<'a>( &self, module_path: &'a [PathSegment], ) -> &'a [PathSegment]

Allows backends to adjust a module path before rendering, e.g., to shorten it according to currenly open namespaces.

Source

fn render(&self, view: &View) -> Rendered

Renders a View into a structured Rendered value, splitting output into module and path parts.

Internally, this uses View::split_at_module to separate module segments from the remaining non-module segments, rendering each with [render_path_segment].

Source

fn separator(&self) -> &str

Returns the string used to join rendered atoms (defaults to "::").

Override to customize separators (e.g., ".").

Source

fn rendered_to_strings( &self, rendered: Rendered, ) -> impl Iterator<Item = String>

Lazy render a view as an iterator of strings.

This chains rendered.module and rendered.path in order.

Source

fn rendered_to_string(&self, rendered: Rendered) -> String

Joins the atoms contained in a Rendered into a single string using separator.

This concatenates rendered.module and rendered.path in order, inserting the separator between atoms.

Source

fn render_string(&self, view: &View) -> String

Convenience: renders a View straight to a single String.

Source

fn render_strings(&self, view: &View) -> impl Iterator<Item = String>

Convenience: renders a View straight to a iterator of Strings.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§