Crate rep_str

Crate rep_str 

Source
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ยง

RepStr
The cache result for a repeatable string.

Traitsยง

IntoRepStr