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: ConditionThe Condition to decide between Self::If::then and Self::If::else.
then: Box<Self>The Self to apply if Self::If::if passes.
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: UrlPartThe 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
value: StringSourceThe StringSource to index Self::StringMap::map with.
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: StringSourceThe NamedPartitioning to search in.
part: UrlPartThe UrlPart whose value to find in the NamedPartitioning.
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: StringSourceThe NamedPartitioning to search in.
parts: Vec<UrlPart>The UrlParts whose value to find in the NamedPartitioning.
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: StringSourceThe NamedPartitioning to search in.
value: StringSourceThe StringSource whose value to find in the NamedPartitioning.
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: StringSourceThe NamedPartitioning to search in.
values: Vec<StringSource>The StringSource whose value to find in the NamedPartitioning.
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
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
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)
Sets UrlPart::Whole.
Join(StringSource)
§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)
§Errors
If the call to BetterUrl::set_scheme returns an error, that error is returned.
SetHost(StringSource)
§Errors
If the call to BetterUrl::set_host returns an error, that error is returned.
SetSubdomain(StringSource)
§Errors
If the call to BetterUrl::set_subdomain returns an error, that error is returned.
SetRegDomain(StringSource)
§Errors
If the call to BetterUrl::set_reg_domain returns an error, that error is returned.
SetDomain(StringSource)
§Errors
If the call to BetterUrl::set_domain returns an error, that error is returned.
SetDomainMiddle(StringSource)
§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)
§Errors
If the call to BetterUrl::set_domain_suffix returns an error, that error is returned.
SetDomainSegment
§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.
SetSubdomainSegment
§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.
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.
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.
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.
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.
EnsureFqdnPeriod
§Errors
If the call to BetterUrl::set_fqdn returns an error, that error is returned.
RemoveFqdnPeriod
§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
§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.
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.
SetRawPathSegment
§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.
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.
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)
§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
§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.
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: StringThe name of the Set in Params::sets to use.
list: StringThe 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: QueryParamSelectorThe query parameter to rename.
to: StringSourceThe 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");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
modification: StringModificationThe 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
modification: StringModificationThe 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");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");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
Locationheader is missing, returns the errorActionError::LocationHeaderNotFound. -
If the call to
std::str::from_utf8returns an error, that error is returned. -
If the call to
BetterUrl::parsereturns an error, that error is returned.
If the call to Cache::write returns an error, that error is returned.
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);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: StringSourceThe name of the var to set.
value: StringSourceThe 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: StringSourceThe name of the var to modify.
modification: StringModificationThe 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: StringSourceThe subject for the cache entry.
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<'de> Action
impl<'de> Action
pub fn deserialize<__D>(__deserializer: __D) -> Result<Action, __D::Error>where
__D: Deserializer<'de>,
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Action
impl<'de> Deserialize<'de> for Action
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Action
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
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more