__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
pub mod serde_option_regex {
use regex::Regex;
use serde::{de, Deserialize, Deserializer, Serializer};
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Regex>, D::Error>
where
D: Deserializer<'de>,
{
let re: Option<String> = Deserialize::deserialize(deserializer)?;
re.map(|re| Regex::new(&re).map_err(de::Error::custom))
.transpose()
}
pub fn serialize<S>(re: &Option<Regex>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if let Some(re) = re {
serializer.serialize_str(&re.to_string())
} else {
serializer.serialize_none()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use regex::Regex;
use serde::{Deserialize, Serialize};
use simple_test_case::test_case;
#[derive(Deserialize, Serialize)]
struct Wrapper {
#[serde(with = "serde_option_regex", default)]
re: Option<Regex>,
}
#[test_case(r#"{"re":"(a|b)*123"}"#; "present")]
#[test_case(r#"{"re":null}"#; "explicit null")]
#[test_case(r#"{}"#; "field missing")]
#[test]
fn serde_deserialize_works(s1: &str) {
let res = serde_json::from_str::<Wrapper>(s1);
assert!(res.is_ok())
}
// Not including the "field missing" case here as we can either serialize None as an explicit
// null (default behaviour) or skip the field, not both. So the Wrapper struct will round trip
// for an explicit null only.
#[test_case(r#"{"re":"(a|b)*123"}"#; "present")]
#[test_case(r#"{"re":null}"#; "explicit null")]
#[test]
fn serde_round_trip_works(s1: &str) {
let w: Wrapper = serde_json::from_str(s1).unwrap();
let s2 = serde_json::to_string(&w).unwrap();
assert_eq!(s1, s2);
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| bin | Folder | 0755 |
|
|
| cli_actions | Folder | 0755 |
|
|
| daemon | Folder | 0755 |
|
|
| protos | Folder | 0755 |
|
|
| snapd_client | Folder | 0755 |
|
|
| lib.rs | File | 2.43 KB | 0644 |
|
| prompt_sequence.rs | File | 12.33 KB | 0644 |
|
| recording.rs | File | 4.6 KB | 0644 |
|
| socket_client.rs | File | 2.47 KB | 0644 |
|
| util.rs | File | 1.78 KB | 0644 |
|