Struct Cache
pub struct Cache { /* private fields */ }
A cache represents a partially computed forward and reverse DFA.
A cache is the key component that differentiates a classical DFA and a
hybrid NFA/DFA (also called a "lazy DFA"). Where a classical DFA builds a
complete transition table that can handle all possible inputs, a hybrid
NFA/DFA starts with an empty transition table and builds only the parts
required during search. The parts that are built are stored in a cache. For
this reason, a cache is a required parameter for nearly every operation on
a Regex.
Caches can be created from their corresponding Regex via
Regex::create_cache. A cache can only be used with either the Regex
that created it, or the Regex that was most recently used to reset it
with Cache::reset. Using a cache with any other Regex may result in
panics or incorrect results.
Implementations
impl Cache
fn new(re: &Regex) -> CacheCreate a new cache for the given
Regex.The cache returned should only be used for searches for the given
Regex. If you want to reuse the cache for anotherRegex, then you must callCache::resetwith thatRegex.fn reset(&mut self, re: &Regex)Reset this cache such that it can be used for searching with the given
Regex(and only thatRegex).A cache reset permits reusing memory already allocated in this cache with a different
Regex.Resetting a cache sets its "clear count" to 0. This is relevant if the
Regexhas been configured to "give up" after it has cleared the cache a certain number of times.Example
This shows how to re-purpose a cache for use with a different
Regex.# if cfg! // miri takes too long use ; let re1 = new?; let re2 = new?; let mut cache = re1.create_cache; assert_eq!; // Using 'cache' with re2 is not allowed. It may result in panics or // incorrect results. In order to re-purpose the cache, we must reset // it with the Regex we'd like to use it with. // // Similarly, after this reset, using the cache with 're1' is also not // allowed. cache.reset; assert_eq!; # Ok::fn forward(&mut self) -> &CacheReturn a reference to the forward cache.
fn reverse(&mut self) -> &CacheReturn a reference to the reverse cache.
fn forward_mut(&mut self) -> &mut CacheReturn a mutable reference to the forward cache.
If you need mutable references to both the forward and reverse caches, then use
Cache::as_parts_mut.fn reverse_mut(&mut self) -> &mut CacheReturn a mutable reference to the reverse cache.
If you need mutable references to both the forward and reverse caches, then use
Cache::as_parts_mut.fn as_parts(&self) -> (&Cache, &Cache)Return references to the forward and reverse caches, respectively.
fn as_parts_mut(&mut self) -> (&mut Cache, &mut Cache)Return mutable references to the forward and reverse caches, respectively.
fn memory_usage(&self) -> usizeReturns the heap memory usage, in bytes, as a sum of the forward and reverse lazy DFA caches.
This does not include the stack size used up by this cache. To compute that, use
std::mem::size_of::<Cache>().
Trait Implementations
impl Clone for Cache
fn clone(&self) -> Self
impl Debug for Cache
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
impl UnwindSafe for Cache
Blanket Implementations
impl<T> Any for Cache
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Cache
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Cache
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Cache
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Cache
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Cache
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Cache
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Cache
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Cache
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>