pub struct Cleaner<'a> {
pub docs: Cow<'a, CleanerDocs>,
pub params: Params<'a>,
pub commons: Cow<'a, Commons>,
pub actions: Cow<'a, [Action]>,
}Expand description
The config that determines all behavior of how URLs are cleaned.
Fields§
§docs: Cow<'a, CleanerDocs>The documentation.
Defaults to an empty CleanerDocs.
params: Params<'a>§commons: Cow<'a, Commons>Basically functions.
Defaults to an empty Commons.
actions: Cow<'a, [Action]>Implementations§
Source§impl<'a> Cleaner<'a>
impl<'a> Cleaner<'a>
Sourcepub fn borrowed(&'a self) -> Self
pub fn borrowed(&'a self) -> Self
Create a new Self that Cow::Borroweds all fields.
Basically a very cheap Clone that you can apply ParamsDiffs to.
Sourcepub fn load_from_file<T: AsRef<Path>>(
path: T,
) -> Result<Cleaner<'static>, GetCleanerError>
pub fn load_from_file<T: AsRef<Path>>( path: T, ) -> Result<Cleaner<'static>, GetCleanerError>
Load Self from a JSON file.
§Errors
If the call to std::fs::read_to_string returns an error, that error is returned.
If the call to serde_json::from_str returns an error, that error is returned.
Sourcepub fn get_default() -> Result<&'static Cleaner<'static>, GetCleanerError>
pub fn get_default() -> Result<&'static Cleaner<'static>, GetCleanerError>
Gets the default Self compiled into the binary itself.
If you know you’re only going to get the default config once, Self::get_default_no_cache is better because you can apply ParamsDiffs to it without Clone::cloneing.
§Errors
If the call to Self::get_default_no_cache returns an error, that error is returned.
If the call to Self::get_default_no_cache returns an error, that error is returned.
§Examples
use url_cleaner_engine::types::*;
Cleaner::get_default().unwrap();Sourcepub fn get_default_no_cache() -> Result<Cleaner<'static>, GetCleanerError>
pub fn get_default_no_cache() -> Result<Cleaner<'static>, GetCleanerError>
Deserializes DEFAULT_CLEANER_STR and returns it without caching.
If you’re getting the default config often and rarely using ParamsDiffs, Self::get_default may be better due to it only deserializing the config once.
§Errors
If the call to serde_json::from_str returns an error, that error is returned.
§Examples
use url_cleaner_engine::types::*;
Cleaner::get_default_no_cache().unwrap();Sourcepub fn load_or_get_default<T: AsRef<Path>>(
path: Option<T>,
) -> Result<Cow<'static, Self>, GetCleanerError>
pub fn load_or_get_default<T: AsRef<Path>>( path: Option<T>, ) -> Result<Cow<'static, Self>, GetCleanerError>
If path is Some, returns the result of Self::load_from_file in a Cow::Owned.
If path is None, returns the result of Self::get_default in a Cow::Borrowed.
§Errors
If the call to Self::load_from_file returns an error, that error is returned.
If the call to Self::get_default returns an error, that error is returned.
§Examples
use url_cleaner_engine::types::*;
assert_eq!(
Cleaner::get_default().unwrap(),
&*Cleaner::load_or_get_default(None::<&str>).unwrap()
);
assert_eq!(
Cleaner::get_default().unwrap(),
&*Cleaner::load_or_get_default(Some("default-cleaner.json")).unwrap()
);Sourcepub fn load_or_get_default_no_cache<T: AsRef<Path>>(
path: Option<T>,
) -> Result<Self, GetCleanerError>
pub fn load_or_get_default_no_cache<T: AsRef<Path>>( path: Option<T>, ) -> Result<Self, GetCleanerError>
If path is Some, returns the result of Self::load_from_file.
If path is None, returns the result of Self::get_default_no_cache.
§Errors
If the call to Self::load_from_file returns an error, that error is returned.
If the call to Self::get_default_no_cache returns an error, that error is returned.
§Examples
use url_cleaner_engine::types::*;
assert_eq!(
Cleaner::get_default_no_cache().unwrap(),
Cleaner::load_or_get_default_no_cache(None::<&str>).unwrap()
);
assert_eq!(
Cleaner::get_default_no_cache().unwrap(),
Cleaner::load_or_get_default_no_cache(Some("default-cleaner.json")).unwrap()
);Sourcepub fn apply(
&self,
task_state: &mut TaskState<'_>,
) -> Result<(), ApplyCleanerError>
pub fn apply( &self, task_state: &mut TaskState<'_>, ) -> Result<(), ApplyCleanerError>
Applies each Action in Self::actions in order to the provided TaskState.
If an error is returned, task_state may be left in a partially modified state.
§Errors
If any call to Action::apply returns an error, that error is returned.
Sourcepub fn assert_suitability(&self)
pub fn assert_suitability(&self)
Asserts the suitability of self to be URL Cleaner’s default config.
Exact behavior is unspecified and changes are not considered breaking.
§Panics
If self is deemed unsuitable to be URL Cleaner’s default config, panics.
§Examples
use url_cleaner_engine::types::*;
Cleaner::get_default().unwrap().assert_suitability();Source§impl<'a> Cleaner<'a>
impl<'a> Cleaner<'a>
Sourcepub fn with_profiles(self, profiles: ProfilesConfig) -> ProfiledCleaner<'a>
pub fn with_profiles(self, profiles: ProfilesConfig) -> ProfiledCleaner<'a>
Convert the Cleaner into a ProfiledCleaner using the specified ProfilesConfig.
Trait Implementations§
Source§impl<'de, 'a> Deserialize<'de> for Cleaner<'a>
impl<'de, 'a> Deserialize<'de> for Cleaner<'a>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<'a> Eq for Cleaner<'a>
impl<'a> StructuralPartialEq for Cleaner<'a>
Auto Trait Implementations§
impl<'a> Freeze for Cleaner<'a>
impl<'a> RefUnwindSafe for Cleaner<'a>
impl<'a> Send for Cleaner<'a>
impl<'a> Sync for Cleaner<'a>
impl<'a> Unpin for Cleaner<'a>
impl<'a> UnwindSafe for Cleaner<'a>
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