Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

Expression Engine for Proccessing Rewrite Rules

Supports a subset of official mod_rewrite expressions.

§Example

use mod_rewrite::Engine;

let mut engine = Engine::default();
engine.add_rules(r#"
    RewriteRule /file/(.*)     /tmp/$1      [L]
    RewriteRule /redirect/(.*) /location/$1 [R=302]
    RewriteRule /blocked/(.*)  -            [F]
"#).expect("failed to process rules");

let uri = "http://localhost/file/my/document.txt";
let result = engine.rewrite(uri).unwrap();
println!("{result:?}");

Implementations§

Source§

impl Engine

Source

pub fn max_iterations(self, iterations: usize) -> Self

Configure max number of loops over entire ruleset during rewrite before error

Default is 10

Source

pub fn add_rules(&mut self, rules: &str) -> Result<&mut Self, ExpressionError>

Parse additonal Expressions to append as ExprGroups to the existing engine.

Source

pub fn rewrite(&self, uri: &str) -> Result<Rewrite, EngineError>

Evaluate the given URI against the configured ExprGroup instances defined and generate a Rewrite response.

This method skips using EngineCtx which is used to suppliment Condition expressions. If you are NOT making use of RewriteCond rules, this method may be simpler to use.

See Engine::rewrite_ctx for more details.

Source

pub fn rewrite_ctx( &self, uri: &str, ctx: &mut EngineCtx<'_>, ) -> Result<Rewrite, EngineError>

Evaluate the given URI against the configured ExprGroup instances defined and generate a Rewrite response.

This method uses an additional EngineCtx which is used to suppliment variables expanded in Condition expressions.

If your engine is using RewriteCond rules, you will want to use this method with a complete EngineCtx. See Engine::rewrite for a simpler alternative.

Trait Implementations§

Source§

impl Debug for Engine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Engine

Source§

fn default() -> Engine

Returns the “default value” for a type. Read more
Source§

impl FromStr for Engine

Source§

type Err = ExpressionError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl UnwindSafe for Engine

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, 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.