regexsolver::execution_profile

Struct ExecutionProfile

source
pub struct ExecutionProfile {
    pub max_number_of_states: usize,
    pub start_execution_time: Option<SystemTime>,
    pub execution_timeout: u128,
    pub max_number_of_terms: usize,
}
Expand description

Hold settings about limitations and constraints of operations execution within the engine.

To apply the settings on the current thread you need to call the following function:

use regexsolver::execution_profile::{ExecutionProfile, ThreadLocalParams};

let execution_profile = ExecutionProfile {
    max_number_of_states: 1,
    start_execution_time: None,
    execution_timeout: 1000,
    max_number_of_terms: 10,
};
 
// Store the settings on the current thread.
ThreadLocalParams::init_profile(&execution_profile);

§Examples:

§Limiting the number of states

use regexsolver::{Term, execution_profile::{ExecutionProfile, ThreadLocalParams}, error::EngineError};

let term1 = Term::from_regex(".*abc.*").unwrap();
let term2 = Term::from_regex(".*def.*").unwrap();

let execution_profile = ExecutionProfile {
    max_number_of_states: 1,
    start_execution_time: None,
    execution_timeout: 1000,
    max_number_of_terms: 10,
};
ThreadLocalParams::init_profile(&execution_profile);

assert_eq!(EngineError::AutomatonHasTooManyStates, term1.intersection(&[term2]).unwrap_err());

§Limiting the number of terms

use regexsolver::{Term, execution_profile::{ExecutionProfile, ThreadLocalParams}, error::EngineError};

let term1 = Term::from_regex(".*abc.*").unwrap();
let term2 = Term::from_regex(".*def.*").unwrap();
let term3 = Term::from_regex(".*hij.*").unwrap();

let execution_profile = ExecutionProfile {
    max_number_of_states: 8192,
    start_execution_time: None,
    execution_timeout: 1000,
    max_number_of_terms: 2,
};
ThreadLocalParams::init_profile(&execution_profile);

assert_eq!(EngineError::TooMuchTerms(2,3), term1.intersection(&[term2, term3]).unwrap_err());

§Limiting the execution time

use regexsolver::{Term, execution_profile::{ExecutionProfile, ThreadLocalParams}, error::EngineError};
use std::time::SystemTime;

let term = Term::from_regex(".*abc.*cdef.*sqdsqf.*").unwrap();

let execution_profile = ExecutionProfile {
    max_number_of_states: 8192,
    start_execution_time: Some(SystemTime::now()),
    execution_timeout: 1,
    max_number_of_terms: 50,
};
ThreadLocalParams::init_profile(&execution_profile);

assert_eq!(EngineError::OperationTimeOutError, term.generate_strings(100).unwrap_err());

Fields§

§max_number_of_states: usize

The maximum number of states that a non-determinitic finite automaton can hold, this is checked during the convertion of regular expression to automaton.

§start_execution_time: Option<SystemTime>

Timestamp of when the execution has started, if this value is not set the operations will never timeout.

§execution_timeout: u128

The longest time in milliseconds that an operation execution can last, there are no guaranties that the exact time will be respected.

§max_number_of_terms: usize

The maximum number of terms that an operation can have.

Implementations§

source§

impl ExecutionProfile

source

pub fn assert_not_timed_out(&self) -> Result<(), EngineError>

Assert that execution_timeout is not exceeded.

Return empty if execution_timeout is not exceeded or if start_execution_time is not set.

Return EngineError::OperationTimeOutError otherwise.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V