Action

Enum Action 

Source
pub enum Action {
Show 73 variants None, Error(String), Debug(Box<Self>), If { if: Condition, then: Box<Self>, else: Option<Box<Self>>, }, All(Vec<Self>), PartMap { part: UrlPart, map: Map<Self>, }, StringMap { value: StringSource, map: Map<Self>, }, PartNamedPartitioning { named_partitioning: StringSource, part: UrlPart, map: Map<Self>, }, FirstMatchingPartNamedPartitioning { named_partitioning: StringSource, parts: Vec<UrlPart>, map: Map<Self>, }, StringNamedPartitioning { named_partitioning: StringSource, value: StringSource, map: Map<Self>, }, FirstMatchingStringNamedPartitioning { named_partitioning: StringSource, values: Vec<StringSource>, map: Map<Self>, }, Repeat { actions: Vec<Action>, limit: u64, }, IgnoreError(Box<Self>), RevertOnError(Box<Self>), TryElse { try: Box<Self>, else: Box<Self>, }, FirstNotError(Vec<Self>), SetWhole(StringSource), Join(StringSource), SetScheme(StringSource), SetHost(StringSource), SetSubdomain(StringSource), SetRegDomain(StringSource), SetDomain(StringSource), SetDomainMiddle(StringSource), SetNotDomainSuffix(StringSource), SetDomainSuffix(StringSource), SetDomainSegment { index: isize, value: StringSource, }, SetSubdomainSegment { index: isize, value: StringSource, }, SetDomainSuffixSegment { index: isize, value: StringSource, }, InsertDomainSegment { index: isize, value: StringSource, }, InsertSubdomainSegment { index: isize, value: StringSource, }, InsertDomainSuffixSegment { index: isize, value: StringSource, }, EnsureFqdnPeriod, RemoveFqdnPeriod, SetPath(StringSource), RemovePathSegment(isize), SetPathSegment { index: isize, value: StringSource, }, InsertPathSegment { index: isize, value: StringSource, }, SetRawPathSegment { index: isize, value: StringSource, }, InsertRawPathSegment { index: isize, value: StringSource, }, RemoveEmptyLastPathSegment, RemoveEmptyLastPathSegmentAndInsertNew(StringSource), RemoveFirstNPathSegments(usize), KeepFirstNPathSegments(usize), RemoveLastNPathSegments(usize), KeepLastNPathSegments(usize), SetQuery(StringSource), SetQueryParam { param: QueryParamSelector, value: StringSource, }, RemoveQuery, RemoveEmptyQuery, RemoveQueryParam(StringSource), AllowQueryParam(StringSource), RemoveQueryParams(HashSet<String>), AllowQueryParams(HashSet<String>), RemoveQueryParamsMatching(StringMatcher), AllowQueryParamsMatching(StringMatcher), RemoveQueryParamsInSetOrStartingWithAnyInList { set: String, list: String, }, RenameQueryParam { from: QueryParamSelector, to: StringSource, }, GetUrlFromQueryParam(StringSource), RemoveFragment, RemoveEmptyFragment, SetPart { part: UrlPart, value: StringSource, }, ModifyPart { part: UrlPart, modification: StringModification, }, ModifyPartIfSome { part: UrlPart, modification: StringModification, }, CopyPart { from: UrlPart, to: UrlPart, }, MovePart { from: UrlPart, to: UrlPart, }, ExpandRedirect { url: Option<StringSource>, headers: HeaderMap, http_client_config_diff: Option<Box<HttpClientConfigDiff>>, }, SetScratchpadFlag { name: StringSource, value: bool, }, SetScratchpadVar { name: StringSource, value: StringSource, }, ModifyScratchpadVar { name: StringSource, modification: StringModification, }, CacheUrl { subject: StringSource, action: Box<Self>, }, Common(CommonCall), CommonCallArg(StringSource),
}
Expand description

Actions are how TaskStates get manipulated to clean URLs.

Please note that, in general, when a Action returns an Err, the TaskState may still be modified. For example:

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::All(vec![
    Action::SetPath("/change".into()),
    Action::Error("This won't revert the above".into()),
    Action::SetPath("/this-wont-happen".into())
]).apply(&mut task_state).unwrap_err();

assert_eq!(task_state.url, "https://example.com/change");

This is because reverting on an error requires keeping a copy of the input state, which is very expensive and, if the error is just going to be returned as the result of the Task, not useful.

If you need to revert the TaskState when an error is returned, use Self::RevertOnError to revert the effects but still return the error, and optionally Self::IgnoreError to ignore the error.

Variants§

§

None

Does nothing.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::None.apply(&mut task_state).unwrap();

assert_eq!(task_state.url, "https://example.com/");
§

Error(String)

Always returns the error ActionError::ExplicitError with the included message.

§Errors

Always returns the error ActionError::ExplicitError.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::Error("...".into()).apply(&mut task_state).unwrap_err();

assert_eq!(task_state.url, "https://example.com/");
§

Debug(Box<Self>)

Prints debug info about the contained Self and the current TaskStateView, then returns its return value.

§Errors

If the call to Self::apply returns an error, that error is returned after the debug info is printed.

§

If

If the call to Self::If::if passes, apply Self::If::then.

If the call to Self::If::if fails and Self::If::else is Some, apply Self::If::else.

§Errors

If the call to Condition::check returns an error, that error is returned.

If the call to Self::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::If {
    r#if  : Condition::Always,
    then  : Box::new(Action::None),
    r#else: Some(Box::new(Action::Error("...".into())))
}.apply(&mut task_state).unwrap();

Action::If {
    r#if  : Condition::Never,
    then  : Box::new(Action::None),
    r#else: Some(Box::new(Action::Error("...".into())))
}.apply(&mut task_state).unwrap_err();

Action::If {
    r#if  : Condition::Always,
    then  : Box::new(Action::None),
    r#else: None
}.apply(&mut task_state).unwrap();

Action::If {
    r#if  : Condition::Never,
    then  : Box::new(Action::None),
    r#else: None
}.apply(&mut task_state).unwrap();

Fields

§if: Condition

The Condition to decide between Self::If::then and Self::If::else.

§then: Box<Self>

The Self to apply if Self::If::if passes.

§else: Option<Box<Self>>

The Self to apply if Self::If::if fails.

Defaults to None.

§

All(Vec<Self>)

Applies the contained Selfs in order.

Please note that if one of the contained Selfs returns an error, previous calls to Self::apply aren’t reverted.

§Errors

If any call to Self::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state);

Action::All(vec![
    Action::SetHost("example2.com".into()),
    Action::Error("...".into()),
    Action::SetHost("example3.com".into()),
]).apply(&mut task_state).unwrap_err();

assert_eq!(task_state.url, "https://example2.com/");
§

PartMap

Gets the value specified by Self::PartMap::part, indexes Self::PartMap::map, and applies the returned Self

If the call to Map::get returns None, does nothing..

§Errors

If the call to Self::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state);

Action::PartMap {
    part: UrlPart::Host,
    map: Map {
        map: [
            ("example.com".into(), Action::Error("...".into()))
        ].into(),
        if_none: None,
        r#else: None
    }
}.apply(&mut task_state).unwrap_err();

Fields

§part: UrlPart

The UrlPart to index Self::PartMap::map with.

§map: Map<Self>

The Map to index with Self::PartMap::part.

§

StringMap

Gets the string specified by Self::StringMap::value, indexes Self::StringMap::map, and applies the returned Self.

If the call to Map::get returns None, does nothing.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to Self::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state);

Action::StringMap {
    value: StringSource::String("a".into()),
    map: Map {
        map: [
            ("a".into(), Action::Error("...".into()))
        ].into(),
        if_none: None,
        r#else: None
    }
}.apply(&mut task_state).unwrap_err();

Fields

§map: Map<Self>

The Map to index with Self::StringMap::value.

§

PartNamedPartitioning

Gets the name of the partition Self::PartNamedPartitioning::part is in in the specified NamedPartitioning, indexes Self::PartNamedPartitioning::map with the partition name, and if the Map has a Self there, applies it.

§Errors

If either call to StringSource::get returns an error, that error is returned.

If either call to StringSource::get returns None, returns the error Action.

If the NamedPartitioning isn’t found, returns the error ActionError::NamedPartitioningNotFound.

If the call to Self::apply returns an error, that error is returned.

Fields

§named_partitioning: StringSource

The NamedPartitioning to search in.

§part: UrlPart

The UrlPart whose value to find in the NamedPartitioning.

§map: Map<Self>

The Map to index.

§

FirstMatchingPartNamedPartitioning

Self::PartNamedPartitioning but uses each UrlPart in Self::FirstMatchingPartNamedPartitioning until a match is found.

§Errors

If either call to StringSource::get returns an error, that error is returned.

If either call to StringSource::get returns None, returns the error Action.

If the NamedPartitioning isn’t found, returns the error ActionError::NamedPartitioningNotFound.

If the call to Self::apply returns an error, that error is returned.

§Examples

use std::borrow::Cow;
use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state, url = "https://abc.example.com", params = Params {
    named_partitionings: Cow::Owned([
        (
            "a".into(),
            NamedPartitioning::try_from_iter([
                ("b".into(), vec![Some("example.com".into())])
            ]).unwrap(),
        )
    ].into()),
    ..Default::default()
});

Action::FirstMatchingPartNamedPartitioning {
    named_partitioning: "a".into(),
    parts: vec![UrlPart::NormalizedHost, UrlPart::RegDomain],
    map: [
        ("b".to_string(), Action::SetPath("/123".into()))
    ].into(),
}.apply(&mut task_state).unwrap();

assert_eq!(task_state.url.path(), "/123");

Fields

§named_partitioning: StringSource

The NamedPartitioning to search in.

§parts: Vec<UrlPart>

The UrlParts whose value to find in the NamedPartitioning.

§map: Map<Self>

The Map to index.

§

StringNamedPartitioning

Gets the name of the partition Self::StringNamedPartitioning::value is in in the specified NamedPartitioning, indexes Self::StringNamedPartitioning::map with the partition name, and if the Map has a Self there, applies it.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

If the NamedPartitioning isn’t found, returns the error ActionError::NamedPartitioningNotFound.

If the call to Self::apply returns an error, that error is returned.

Fields

§named_partitioning: StringSource

The NamedPartitioning to search in.

§value: StringSource

The StringSource whose value to find in the NamedPartitioning.

§map: Map<Self>

The Map to index.

§

FirstMatchingStringNamedPartitioning

Self::StringNamedPartitioning but uses each StringSource in Self::FirstMatchingStringNamedPartitioning until a match is found.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

If the NamedPartitioning isn’t found, returns the error ActionError::NamedPartitioningNotFound.

If the call to Self::apply returns an error, that error is returned.

§Examples

use std::borrow::Cow;
use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state, url = "https://abc.example.com", params = Params {
    named_partitionings: Cow::Owned([
        (
            "a".into(),
            NamedPartitioning::try_from_iter([
                ("b".into(), vec![Some("example.com".into())])
            ]).unwrap(),
        )
    ].into()),
    ..Default::default()
});

Action::FirstMatchingStringNamedPartitioning {
    named_partitioning: "a".into(),
    values: vec![StringSource::Part(UrlPart::NormalizedHost), StringSource::Part(UrlPart::RegDomain)],
    map: [
        ("b".to_string(), Action::SetPath("/123".into()))
    ].into(),
}.apply(&mut task_state).unwrap();

assert_eq!(task_state.url.path(), "/123");

Fields

§named_partitioning: StringSource

The NamedPartitioning to search in.

§values: Vec<StringSource>

The StringSource whose value to find in the NamedPartitioning.

§map: Map<Self>

The Map to index.

§

Repeat

Repeat Self::Repeat::actions until either the TaskState::url and TaskState::scratchpad end up in the same state or the rules were executed Self::Repeat::limit times.

§Errors

If any call to Self::apply returns an error, that error is returned.

Fields

§actions: Vec<Action>

The Selfs to repeat.

§limit: u64

The maximum amount of times to repeat.

Defaults to 10.

§

IgnoreError(Box<Self>)

If the contained Self returns an error, ignore it.

Does not revert any successful calls to Self::apply. For that, also use Self::RevertOnError.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::IgnoreError(Box::new(
    Action::RevertOnError(Box::new(
        Action::All(vec![
            Action::SetPath("/change".into()),
            Action::Error("This won't revert the above".into()),
            Action::SetPath("/wont-happen".into())
        ])
    ))
)).apply(&mut task_state).unwrap(); // Error is ignored.

assert_eq!(task_state.url, "https://example.com/"); // The first `Action::SetPath` is reverted.
§

RevertOnError(Box<Self>)

If the contained Self returns an error, revert the TaskState to its previous state then return the error.

To ignore errors, put this in a Self::IgnoreError.

§Errors

If the call to Self::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::RevertOnError(Box::new(
    Action::All(vec![
        Action::SetPath("/change".into()),
        Action::Error("This won't revert the above".into()),
        Action::SetPath("/wont-happen".into())
    ])
)).apply(&mut task_state).unwrap_err(); // Still returns an error.

assert_eq!(task_state.url, "https://example.com/"); // The first `Action::SetPath` is reverted.
§

TryElse

If Self::TryElse::try’s call to Self::apply returns an error, apply Self::TryElse::else.

§Errors

If both calls to Self::apply return errors, both errors are returned in a ActionError::TryElseError.

Fields

§try: Box<Self>

The Self to try first.

§else: Box<Self>

The Self to try if Self::TryElse::try returns an error.

§

FirstNotError(Vec<Self>)

Applies the contained Selfs in order, stopping as soon as a call to Self::apply doesn’t return an error.

§Errors

If all calls to Self::apply return errors, all errors are returned in a ActionError::FirstNotErrorErrors.

§

SetWhole(StringSource)

§

Join(StringSource)

Url::join.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to Url::join returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com/a/b/c");

Action::Join("..".into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/a/");


url_cleaner_engine::task_state!(task_state, url = "https://example.com/a/b/c/");

Action::Join("..".into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/a/b/");
§

SetScheme(StringSource)

BetterUrl::set_scheme.

§Errors

If the call to BetterUrl::set_scheme returns an error, that error is returned.

§

SetHost(StringSource)

BetterUrl::set_host.

§Errors

If the call to BetterUrl::set_host returns an error, that error is returned.

§

SetSubdomain(StringSource)

BetterUrl::set_subdomain.

§Errors

If the call to BetterUrl::set_subdomain returns an error, that error is returned.

§

SetRegDomain(StringSource)

BetterUrl::set_reg_domain.

§Errors

If the call to BetterUrl::set_reg_domain returns an error, that error is returned.

§

SetDomain(StringSource)

BetterUrl::set_domain.

§Errors

If the call to BetterUrl::set_domain returns an error, that error is returned.

§

SetDomainMiddle(StringSource)

BetterUrl::set_domain_middle.

§Errors

If the call to BetterUrl::set_domain_middle returns an error, that error is returned.

§

SetNotDomainSuffix(StringSource)

BetterUrl::set_not_domain_suffix.

§Errors

If the call to BetterUrl::set_not_domain_suffix returns an error, that error is returned.

§

SetDomainSuffix(StringSource)

BetterUrl::set_domain_suffix.

§Errors

If the call to BetterUrl::set_domain_suffix returns an error, that error is returned.

§

SetDomainSegment

BetterUrl::domain_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::domain_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert the segment at.

§value: StringSource

The value to insert.

§

SetSubdomainSegment

BetterUrl::subdomain_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::subdomain_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert the segment at.

§value: StringSource

The value to insert.

§

SetDomainSuffixSegment

BetterUrl::domain_suffix_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::domain_suffix_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert the segment at.

§value: StringSource

The value to insert.

§

InsertDomainSegment

BetterUrl::insert_domain_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::insert_domain_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert the segment at.

§value: StringSource

The value to insert.

§

InsertSubdomainSegment

BetterUrl::insert_subdomain_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::insert_subdomain_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert the segment at.

§value: StringSource

The value to insert.

§

InsertDomainSuffixSegment

BetterUrl::insert_domain_suffix_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::insert_domain_suffix_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert the segment at.

§value: StringSource

The value to insert.

§

EnsureFqdnPeriod

BetterUrl::set_fqdn to true

§Errors

If the call to BetterUrl::set_fqdn returns an error, that error is returned.

§

RemoveFqdnPeriod

BetterUrl::set_fqdn to false

§Errors

If the call to BetterUrl::set_fqdn returns an error, that error is returned.

§

SetPath(StringSource)

§

RemovePathSegment(isize)

Removes the specified UrlPart::PathSegment.

§Errors

If the call to BetterUrl::set_path_segment returns an error, that error is returned.

§

SetPathSegment

BetterUrl::set_path_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::set_path_segment returns an error, that error is returned.

Fields

§index: isize
§value: StringSource

The value to set it to.

§

InsertPathSegment

BetterUrl::insert_path_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error ActionError.

If the call to BetterUrl::insert_path_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert it at.

§value: StringSource

The value to insert.

§

SetRawPathSegment

BetterUrl::set_path_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::set_path_segment returns an error, that error is returned.

Fields

§index: isize
§value: StringSource

The value to set it to.

§

InsertRawPathSegment

BetterUrl::insert_path_segment.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error ActionError.

If the call to BetterUrl::insert_path_segment returns an error, that error is returned.

Fields

§index: isize

The index to insert it at.

§value: StringSource

The value to insert.

§

RemoveEmptyLastPathSegment

PathSegmentsMut::pop_if_empty.

§Errors

If the call to BetterUrl::path_segments_mut returns an error, that error is returned.

§

RemoveEmptyLastPathSegmentAndInsertNew(StringSource)

PathSegmentsMut::pop_if_empty and PathSegmentsMut::push.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error ActionError.

If the call to BetterUrl::path_segments_mut returns an error, that error is returned.

§

RemoveFirstNPathSegments(usize)

Remove the first n path segments.

The number of path segments after this succeeds is equal to the number of path segments before this is applied minus n.

Because a path can’t have zero segments, this means trying to remove all segments counts as not having enough segments. If this is a serious ergonomics issue for you, I’ll prioritize making a workaround.

§Errors

If the call to BetterUrl::remove_first_n_path_segments returns an error, that error is returned.

§

KeepFirstNPathSegments(usize)

Keep the first n path segments.

The number of path segments after this succeeds is equal to n.

Because a path can’t have zero segments, this means trying to keep zero segments always errors. This is easy to just not do.

§Errors

If the call to BetterUrl::keep_first_n_path_segments returns an error, that error is returned.

§

RemoveLastNPathSegments(usize)

Remove the last n path segments.

The number of path segments after this succeeds is equal to the number of path segments before this is applied minus n.

Because a path can’t have zero segments, this means trying to remove all segments counts as not having enough segments. If this is a serious ergonomics issue for you, I’ll prioritize making a workaround.

§Errors

If the call to BetterUrl::remove_last_n_path_segments returns an error, that error is returned.

§

KeepLastNPathSegments(usize)

Keep the last n path segments.

The number of path segments after this succeeds is equal to n.

Because a path can’t have zero segments, this means trying to keep zero segments always errors. This is easy to just not do.

§Errors

If the call to BetterUrl::keep_last_n_path_segments returns an error, that error is returned.

§

SetQuery(StringSource)

BetterUrl::set_query.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::set_query returns an error, that error is returned.

§

SetQueryParam

BetterUrl::set_query_param

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to BetterUrl::set_query_param returns an error, that error is returned.

Fields

§param: QueryParamSelector

The query param to set.

§value: StringSource

The value to set it to.

§

RemoveQuery

Remove the entire UrlPart::Query.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?a=2");

Action::RemoveQuery.apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/");
§

RemoveEmptyQuery

If the Url::query is Some(""), set it to None.

§

RemoveQueryParam(StringSource)

Removes all query parameters with the specified name.

For performance reasons, if the resulting query is empty, this instead sets it to None.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?a=2&b=3&a=4&c=5");

Action::RemoveQueryParam("a".into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("b=3&c=5"));
Action::RemoveQueryParam("b".into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("c=5"));
Action::RemoveQueryParam("c".into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), None);
§

AllowQueryParam(StringSource)

Keeps all query parameters with the specified name.

For performance reasons, if the resulting query is empty, this instead sets it to None.

§

RemoveQueryParams(HashSet<String>)

Removes all query params with names in the specified HashSet.

For performance reasons, if the resulting query is empty, this instead sets it to None.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?a=2&b=3&%61=4&c=5");

Action::RemoveQueryParams(["a".to_string(), "b".to_string()].into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("c=5"));
Action::RemoveQueryParams(["c".to_string()].into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), None);
§

AllowQueryParams(HashSet<String>)

Keeps only query params with names in the specified HashSet.

For performance reasons, if the resulting query is empty, this instead sets it to None.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?a=2&b=3&%61=4&c=5");

Action::AllowQueryParams(["a".to_string(), "b".to_string()].into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("a=2&b=3&%61=4"));
Action::AllowQueryParams(["c".to_string()].into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), None);
§

RemoveQueryParamsMatching(StringMatcher)

Removes all query params with names matching the specified StringMatcher.

For performance reasons, if the resulting query is empty, this instead sets it to None.

§Errors

If the call to StringMatcher::check returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?a=2&b=3&%61=4&c=5");

Action::RemoveQueryParamsMatching(StringMatcher::Is("a".into())).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("b=3&c=5"));
Action::RemoveQueryParamsMatching(StringMatcher::Is("b".into())).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("c=5"));
Action::RemoveQueryParamsMatching(StringMatcher::Is("c".into())).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), None);
§

AllowQueryParamsMatching(StringMatcher)

Keeps only query params with names matching the specified StringMatcher.

For performance reasons, if the resulting query is empty, this instead sets it to None.

§Errors

If the call to StringMatcher::check returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?a=2&b=3&%61=4&c=5");

Action::AllowQueryParamsMatching(StringMatcher::Is("a".into())).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), Some("a=2&%61=4"));
Action::AllowQueryParamsMatching(StringMatcher::Is("b".into())).apply(&mut task_state).unwrap();
assert_eq!(task_state.url.query(), None);
§

RemoveQueryParamsInSetOrStartingWithAnyInList

Extreme shorthand for handling universal query parameters.

§Errors

If the Set isn’t found, returns the error ActionError::SetNotFound.

If the list isn’t found, returns the error ActionError::ListNotFound.

Fields

§set: String

The name of the Set in Params::sets to use.

§list: String

The name of the list in Params::lists to use.

§

RenameQueryParam

Rename the specified query parameter to the specified name.

§Errors

If the call to BetterUrl::rename_query_param returns an error, that error is returned.

Fields

§from: QueryParamSelector

The query parameter to rename.

§to: StringSource

The name to rename it to.

§

GetUrlFromQueryParam(StringSource)

Sets UrlPart::Whole to the value of the first query parameter with a name determined by the TaskState.

§Errors

If the URL doesn’t have a query, returns the error ActionError::NoQuery.

If the specified query param isn’t found, returns the error ActionError::QueryParamNotFound.

If the specified query param doesn’t have a value, returns the error ActionError::QueryParamNoValue.

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

If no matching query parameter is found, returns the error ActionError::QueryParamNotFound.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com?redirect=https://example.com/2");

Action::GetUrlFromQueryParam("redirect".into()).apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/2");

Action::GetUrlFromQueryParam("redirect".into()).apply(&mut task_state).unwrap_err();
§

RemoveFragment

Removes the UrlPart::Fragment.

§

RemoveEmptyFragment

If the Url::fragment is Some(""), set it to None.

§

SetPart

Sets the specified UrlPart to the specified value.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to UrlPart::set returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;
url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::SetPart {part: UrlPart::Path, value: "abc".into()}.apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/abc");

Fields

§part: UrlPart

The part to set the value of.

§value: StringSource

The value to set the part to.

§

ModifyPart

If the specified UrlPart is Some, applies Self::ModifyPart::modification.

If the part is None, does nothing.

§Errors

If the call to StringModification::apply returns an error, that error is returned.

If the call to UrlPart::set returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state, url = "https://example.com");

Action::ModifyPart {part: UrlPart::Path, modification: StringModification::Set("abc".into())}.apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/abc");

Action::ModifyPart {part: UrlPart::Query, modification: StringModification::Set("abc".into())}.apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/abc?abc");

Fields

§part: UrlPart

The part to modify.

§modification: StringModification

The modification to apply to the part.

§

ModifyPartIfSome

If the specified UrlPart is Some, apply Self::ModifyPartIfSome::modification.

§Errors

If the call to StringModification::apply returns an error, that error is returned.

If the call to UrlPart::set returns an error, that error is returned.

Fields

§part: UrlPart

The UrlPart to modify.

§modification: StringModification

The StringModification to apply.

§

CopyPart

Sets Self::CopyPart::to to the value of Self::CopyPart::from, leaving Self::CopyPart::from unchanged.

§Errors

If the call to UrlPart::set returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state, url = "https://example.com/abc#def");

Action::CopyPart {from: UrlPart::Fragment, to: UrlPart::Path}.apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/def#def");

Fields

§from: UrlPart

The part whose value to copy.

§to: UrlPart

The part whose value to set.

§

MovePart

Sets Self::CopyPart::to to the value of Self::CopyPart::from, then sets Self::CopyPart::from to None.

§Errors

If either call to UrlPart::set returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state, url = "https://example.com/abc#def");

Action::MovePart {from: UrlPart::Fragment, to: UrlPart::Path}.apply(&mut task_state).unwrap();
assert_eq!(task_state.url, "https://example.com/def");

Fields

§from: UrlPart

The part whose value to move.

§to: UrlPart

The part whose value to set.

§

ExpandRedirect

Sends an HTTP GET request to the current TaskState::url, and sets it either to the value of the response’s Location header (if the response is a redirect) or the final URL after redirects.

If the cache feature flag is enabled, caches the operation with the subject redirect, the key set to the input URL, and the value set to the returned URL.

§Errors

If the call to Cache::read returns an error, that error is returned.

If the call to Cache::read returns None, returns the error ActionError::CachedUrlIsNone.

If the call to BetterUrl::parse returns an error, that error is returned.

If the call to TaskStateView::http_client returns an error, that error is returned.

If the call to reqwest::blocking::RequestBuilder::send returns an error, that error is returned.

If the response is a redirect:

If the call to Cache::write returns an error, that error is returned.

Fields

§url: Option<StringSource>

If Some, expand this URL instead.

Defaults to None.

§headers: HeaderMap

The extra headers to send.

Defaults to an empty HeaderMap.

§http_client_config_diff: Option<Box<HttpClientConfigDiff>>

The HttpClientConfigDiff to apply.

Defaults to None.

Boxed because it’s massive.

§

SetScratchpadFlag

Sets the specified Scratchpad::flags to Self::SetScratchpadFlag::value.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state);

assert_eq!(task_state.scratchpad.flags.contains("abc"), false);
Action::SetScratchpadFlag {name: "abc".into(), value: true}.apply(&mut task_state).unwrap();
assert_eq!(task_state.scratchpad.flags.contains("abc"), true);

Fields

§name: StringSource

The name of the flag to set.

§value: bool

The value to set the flag to.

§

SetScratchpadVar

Sets the specified Scratchpad::vars to Self::SetScratchpadVar::value.

§Errors

If the call to StringSource::get returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state);

Action::SetScratchpadVar {name: "abc".into(), value: "def".into()}.apply(&mut task_state).unwrap();
assert_eq!(task_state.scratchpad.vars.get("abc").map(|x| &**x), Some("def"));
Action::SetScratchpadVar {name: "abc".into(), value: StringSource::None}.apply(&mut task_state).unwrap();
assert_eq!(task_state.scratchpad.vars.get("abc").map(|x| &**x), None);

Fields

§name: StringSource

The name of the var to set.

§value: StringSource

The value to set the var to.

§

ModifyScratchpadVar

If the specified Scratchpad::vars is Some, applies Self::ModifyScratchpadVar::modification.

If the part is None, does nothing.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

If the call to StringModification::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state);

Action::ModifyScratchpadVar {name: "abc".into(), modification: StringModification::Set("123".into())}.apply(&mut task_state).unwrap();
assert_eq!(task_state.scratchpad.vars.get("abc").map(|x| &**x), Some("123"));
Action::ModifyScratchpadVar {name: "abc".into(), modification: StringModification::Set(StringSource::None)}.apply(&mut task_state).unwrap();
assert_eq!(task_state.scratchpad.vars.get("abc").map(|x| &**x), None);

Fields

§name: StringSource

The name of the var to modify.

§modification: StringModification

The modification to apply.

§

CacheUrl

If an entry with a subject of Self::CacheUrl::subject and a key of TaskState::url exists in the TaskState::cache, sets the URL to the entry’s value.

If no such entry exists, applies Self::CacheUrl::action and inserts a new entry equivalent to applying it.

Does not cache the TaskState::scratchpad.

§Errors

If the call to Cache::read returns an error, that error is returned.

If the call to Cache::read returns None, returns the error ActionError::CachedUrlIsNone.

If the call to BetterUrl::parse returns an error, that error is returned.

If the call to Self::apply returns an error, that error is returned.

If the call to Cache::write returns an error, that error is returned.

Fields

§subject: StringSource

The subject for the cache entry.

§action: Box<Self>

The action to apply and cache.

§

Common(CommonCall)

Applies a Self from TaskState::commons’s Commons::actions.

§Errors

If the call to StringSource::get returns an error, that error is returned.

If the call to StringSource::get returns None, returns the error Action.

If the common Self isn’t found, returns the error ActionError::CommonActionNotFound.

If the call to CommonCallArgsSource::build returns an error, that error is returned.

If the call to Self::apply returns an error, that error is returned.

§Examples

use url_cleaner_engine::types::*;

url_cleaner_engine::task_state!(task_state, commons = Commons {
    actions: [("abc".into(), Action::None)].into(),
    ..Default::default()
});

Action::Common(CommonCall {name: Box::new("abc".into()), args: Default::default()}).apply(&mut task_state).unwrap();
§

CommonCallArg(StringSource)

Gets a Self from TaskStateView::common_args’s CommonCallArgs::actions and applies it.

§Errors

If TaskStateView::common_args is None, returns the error ActionError::NotInCommonContext.

If the common call arg Self isn’t found, returns the error ActionError::CommonCallArgActionNotFound.

If the call to Self::apply returns an error, that error is returned.

Implementations§

Source§

impl Action

Source

pub fn serialize<__S>( __self: &Action, __serializer: __S, ) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Source§

impl<'de> Action

Source

pub fn deserialize<__D>(__deserializer: __D) -> Result<Action, __D::Error>
where __D: Deserializer<'de>,

Source§

impl Action

Source

pub fn apply(&self, task_state: &mut TaskState<'_>) -> Result<(), ActionError>

Applies the specified variant of Self.

If an error is returned, task_state may be left in a partially modified state.

§Errors

See each variant of Self for when each variant returns an error.

Trait Implementations§

Source§

impl Clone for Action

Source§

fn clone(&self) -> Action

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Action

Source§

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

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

impl<'de> Deserialize<'de> for Action

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromStr for Action

Source§

type Err = NonDefaultableActionVariant

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
Source§

impl PartialEq for Action

Source§

fn eq(&self, other: &Action) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Action

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Action

Source§

impl StructuralPartialEq for Action

Auto Trait Implementations§

§

impl !Freeze for Action

§

impl RefUnwindSafe for Action

§

impl Send for Action

§

impl Sync for Action

§

impl Unpin for Action

§

impl UnwindSafe for Action

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,