Skip to main content

formatted_truncate

Function formatted_truncate 

Source
pub fn formatted_truncate(content: &str, policy: TruncationPolicy) -> String
Expand description

Truncate content to policy if needed, prefixing a warning header that states the original token count and total line count. Output already within the policy is returned unchanged.

The returned string, header included, never exceeds the policy’s byte budget.

§Examples

use universal_agent_runtime::uar::runtime::context::truncate::{formatted_truncate, TruncationPolicy, WARNING_HEADER_PREFIX};
assert_eq!(formatted_truncate("ok", TruncationPolicy::Bytes(100)), "ok");
let big = "x".repeat(10_000);
let out = formatted_truncate(&big, TruncationPolicy::Bytes(500));
assert!(out.len() <= 500);
assert!(out.starts_with(WARNING_HEADER_PREFIX));