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
Renderedor a single flatString.
§Terminology
A path segment can be:
- named: carries a
Symbolthat can be printed as-is, - unnamed: carries an
UnnamedPathSegmentPayload(likeImpl,Closure, …), which must be turned into aSymbolfirst (seeRenderView::render_unnamed_path_segment_payload).
§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§
Sourcefn reserved_keywords() -> &'static HashSet<String>
fn reserved_keywords() -> &'static HashSet<String>
List of reserved keywords that will be escaped when rendering
Sourcefn is_reserved_keyword(id: &str) -> bool
fn is_reserved_keyword(id: &str) -> bool
Check if a string is a reserved keyword that needs escaping
Sourcefn should_escape(id: &str) -> bool
fn should_escape(id: &str) -> bool
Check if a string needs escaping
Sourcefn escape(id: &str) -> String
fn escape(id: &str) -> String
Escape a string if it needs escaping according to Self::should_escape
Sourcefn render_unnamed_path_segment_payload(
&self,
unnamed: UnnamedPathSegmentPayload,
) -> Symbol
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.
Sourcefn render_path_segment_payload(&self, payload: PathSegmentPayload) -> Symbol
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].
Sourcefn render_path_segment(&self, seg: &PathSegment) -> Vec<String>
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.
Sourcefn render_suffix(&self, suffix: &ReservedSuffix) -> String
fn render_suffix(&self, suffix: &ReservedSuffix) -> String
Renders the optional suffix
Sourcefn relativize_module_path<'a>(
&self,
module_path: &'a [PathSegment],
) -> &'a [PathSegment]
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.
Sourcefn render(&self, view: &View) -> Rendered
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].
Sourcefn separator(&self) -> &str
fn separator(&self) -> &str
Returns the string used to join rendered atoms (defaults to "::").
Override to customize separators (e.g., ".").
Sourcefn rendered_to_strings(
&self,
rendered: Rendered,
) -> impl Iterator<Item = String>
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.
Sourcefn rendered_to_string(&self, rendered: Rendered) -> String
fn rendered_to_string(&self, rendered: Rendered) -> String
Sourcefn render_string(&self, view: &View) -> String
fn render_string(&self, view: &View) -> String
Convenience: renders a View straight to a single String.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".