Expand description
This is a crate for caching a repeat pattern of a str
with only one allocation by generate a new RepStr
struct
this crate provides.
Example 1: Crate RepStr directly.
use rep_str::RepStr;
let repstr = rep_str::RepStr::new("#", 50); // generate a RepStr object with max repeat time 50
assert!("##########" == repstr.repeat_unwrap(10));
assert!("####################" == repstr.repeat_unwrap(20));
// no extra allocation would occurs:
assert!(repstr.repeat_unwrap(20).as_ptr() == repstr.repeat(12).unwrap().as_ptr())
// repstr.repeat_unwrap(51) // panic!
Example 2: Crate RepStr by IntoRepStr trait
use rep_str::IntoRepStr;
let repstr = "🦀".repeat_cache(20);
assert!(Some("🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀") == repstr.repeat(20));
assert!(None == repstr.repeat(21));
Structs
The cache result for a repeatable string.