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§
Implementations§
Source§impl<'de, T: Deserialize<'de>> SoftErrors<T>
impl<'de, T: Deserialize<'de>> SoftErrors<T>
pub fn new_all() -> Self
pub fn new_list() -> Self
pub fn skip_all(&self) -> bool
pub fn add_soft_error(&mut self, soft_error: T)
pub fn with_soft_error(self, soft_error: T) -> Self
pub fn maybe_soft_error_list(&self) -> Option<&Vec<T>>
pub fn maybe_soft_error_list_mut(&mut self) -> Option<&mut Vec<T>>
Source§impl<'de, T: Deserialize<'de> + PartialEq> SoftErrors<T>
impl<'de, T: Deserialize<'de> + PartialEq> SoftErrors<T>
Trait Implementations§
Source§impl<T: Clone> Clone for SoftErrors<T>
impl<T: Clone> Clone for SoftErrors<T>
Source§fn clone(&self) -> SoftErrors<T>
fn clone(&self) -> SoftErrors<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for SoftErrors<T>
impl<T: Debug> Debug for SoftErrors<T>
Source§impl<'de, T: Deserialize<'de>> Default for SoftErrors<T>
impl<'de, T: Deserialize<'de>> Default for SoftErrors<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for SoftErrors<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for SoftErrors<T>
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: PartialEq> PartialEq for SoftErrors<T>
impl<T: PartialEq> PartialEq for SoftErrors<T>
Source§impl<T> Serialize for SoftErrors<T>where
T: Serialize,
impl<T> Serialize for SoftErrors<T>where
T: Serialize,
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> 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
Mutably borrows from an owned value. Read more