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("<script>"));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.