SoftErrors

Enum SoftErrors 

Source
pub enum SoftErrors<T> {
    All,
    List(Vec<T>),
}
Expand description

Soft errors deserializer wrapper for URL query strings.

§Example


use plugx_config::{
    loader::{SoftErrors, deserialize_query_string},
    ext::{url::Url, serde::Deserialize},
};

// Define an enum for your own errors
#[derive(Debug, PartialEq, Deserialize)]
enum MySoftErrors {
    NotFound,
    Permission,
    Empty,
}

// Define a struct for your own options
// Include your own errors inside your options
#[derive(Debug, PartialEq, Deserialize)]
struct MyOptions {
    // The value should be string `all` or dot seperated values of `MySoftErrors`
    skip_errors: SoftErrors<MySoftErrors>,
    // Other options ...
}

// `deserialize_query_string` function needs loader name to generate a good descriptive error
let loader_name = "file-loader";

let url = Url::try_from("file://etc/config/file.toml?skip_errors=all").expect("Valid URL");
let options: MyOptions = deserialize_query_string(loader_name, &url).expect("Parse options");
assert_eq!(options, MyOptions{skip_errors: SoftErrors::new_all()});
assert!(options.skip_errors.skip_all());

let url = Url::try_from("file://etc/config/file.toml?skip_errors=NotFound.Permission").expect("Valid URL");
let options: MyOptions = deserialize_query_string(loader_name, &url).expect("Parse options");
let skip_errors = options.skip_errors;
assert!(skip_errors.contains(&MySoftErrors::NotFound));
assert!(skip_errors.contains(&MySoftErrors::Permission));
assert!(!skip_errors.contains(&MySoftErrors::Empty));
assert!(!skip_errors.skip_all());
assert_eq!(
    skip_errors.maybe_soft_error_list(),
      Some(&Vec::from([MySoftErrors::NotFound, MySoftErrors::Permission]))
);

Variants§

§

All

§

List(Vec<T>)

Implementations§

Source§

impl<'de, T: Deserialize<'de>> SoftErrors<T>

Source

pub fn new_all() -> Self

Source

pub fn new_list() -> Self

Source

pub fn skip_all(&self) -> bool

Source

pub fn add_soft_error(&mut self, soft_error: T)

Source

pub fn with_soft_error(self, soft_error: T) -> Self

Source

pub fn maybe_soft_error_list(&self) -> Option<&Vec<T>>

Source

pub fn maybe_soft_error_list_mut(&mut self) -> Option<&mut Vec<T>>

Source§

impl<'de, T: Deserialize<'de> + PartialEq> SoftErrors<T>

Source

pub fn contains(&self, soft_error: &T) -> bool

Trait Implementations§

Source§

impl<T: Clone> Clone for SoftErrors<T>

Source§

fn clone(&self) -> SoftErrors<T>

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<T: Debug> Debug for SoftErrors<T>

Source§

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

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

impl<'de, T: Deserialize<'de>> Default for SoftErrors<T>

Source§

fn default() -> Self

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

impl<'de, T: Deserialize<'de>> Deserialize<'de> for SoftErrors<T>

Source§

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

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

impl<T: PartialEq> PartialEq for SoftErrors<T>

Source§

fn eq(&self, other: &SoftErrors<T>) -> 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<T> Serialize for SoftErrors<T>
where T: Serialize,

Source§

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

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

impl<T> StructuralPartialEq for SoftErrors<T>

Auto Trait Implementations§

§

impl<T> Freeze for SoftErrors<T>

§

impl<T> RefUnwindSafe for SoftErrors<T>
where T: RefUnwindSafe,

§

impl<T> Send for SoftErrors<T>
where T: Send,

§

impl<T> Sync for SoftErrors<T>
where T: Sync,

§

impl<T> Unpin for SoftErrors<T>
where T: Unpin,

§

impl<T> UnwindSafe for SoftErrors<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> 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> 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> 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<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>,