Skip to main content

Module display

Module display 

Source
Expand description

zero-allocation Display wrappers for all encoding contexts.

every for_* function allocates a String. when embedding encoded output in a larger format string (e.g., format!("<p>{}</p>", for_html(s))), the intermediate string is immediately consumed and discarded — a wasted allocation.

the display_* functions return lightweight wrappers that implement Display by delegating to the corresponding write_* function. this enables zero-allocation inline formatting:

use contextual_encoder::display_html;

let user_input = "<script>alert('xss')</script>";
// one allocation (the final String), zero intermediate allocations
let output = format!("<p>{}</p>", display_html(user_input));
assert!(output.contains("&lt;script&gt;"));

each display_* wrapper encodes identically to its for_* / write_* counterpart. see the corresponding for_* function for encoding rules.

Functions§

display_cdata
zero-allocation display wrapper for for_cdata.
display_css_string
zero-allocation display wrapper for for_css_string.
display_css_url
zero-allocation display wrapper for for_css_url.
display_go_byte_string
zero-allocation display wrapper for for_go_byte_string.
display_go_char
zero-allocation display wrapper for for_go_char.
display_go_string
zero-allocation display wrapper for for_go_string.
display_html
zero-allocation display wrapper for for_html.
display_html_attribute
zero-allocation display wrapper for for_html_attribute.
display_html_content
zero-allocation display wrapper for for_html_content.
display_html_unquoted_attribute
zero-allocation display wrapper for for_html_unquoted_attribute.
display_java
zero-allocation display wrapper for for_java.
display_javascript
zero-allocation display wrapper for for_javascript.
display_javascript_attribute
zero-allocation display wrapper for for_javascript_attribute.
display_javascript_block
zero-allocation display wrapper for for_javascript_block.
display_javascript_source
zero-allocation display wrapper for for_javascript_source.
display_js_template
zero-allocation display wrapper for for_js_template.
display_json
zero-allocation display wrapper for for_json.
display_python_bytes
zero-allocation display wrapper for for_python_bytes.
display_python_raw_string
zero-allocation display wrapper for for_python_raw_string.
display_python_string
zero-allocation display wrapper for for_python_string.
display_ruby_string
zero-allocation display wrapper for for_ruby_string.
display_rust_byte_string
zero-allocation display wrapper for for_rust_byte_string.
display_rust_char
zero-allocation display wrapper for for_rust_char.
display_rust_string
zero-allocation display wrapper for for_rust_string.
display_sql
zero-allocation display wrapper for for_sql.
display_sql_backslash
zero-allocation display wrapper for for_sql_backslash.
display_uri_component
zero-allocation display wrapper for for_uri_component.
display_xml
zero-allocation display wrapper for for_xml.
display_xml11
zero-allocation display wrapper for for_xml11.
display_xml11_attribute
zero-allocation display wrapper for for_xml11_attribute.
display_xml11_content
zero-allocation display wrapper for for_xml11_content.
display_xml_attribute
zero-allocation display wrapper for for_xml_attribute.
display_xml_comment
zero-allocation display wrapper for for_xml_comment.
display_xml_content
zero-allocation display wrapper for for_xml_content.