Mountain/ApplicationState/Internal/Serialization/URLDeserializer.rs
1//! # URLDeserializer Module (Internal)
2//!
3//! ## RESPONSIBILITIES
4//! Deserializes JSON strings to URL objects for data transfer and storage.
5//!
6//! ## ARCHITECTURAL ROLE
7//! URLDeserializer is part of the **Internal::Serialization** module,
8//! providing URL deserialization utilities.
9//!
10//! ## KEY COMPONENTS
11//! - DeserializeURL: Function to deserialize JSON to URL
12//!
13//! ## ERROR HANDLING
14//! - Returns Result with URL or String error on parse failure
15//!
16//! ## LOGGING
17//! Operations are logged at appropriate levels (debug).
18//!
19//! ## PERFORMANCE CONSIDERATIONS
20//! - Efficient deserialization
21//! - Proper error handling
22//!
23//! ## TODO
24//! - [ ] Add URL validation after deserialization
25//! - [ ] Implement custom error recovery
26//! - [ ] Add performance metrics
27
28use serde::{Deserializer, de::Deserialize};
29use url::Url;
30use log::debug;
31
32/// Deserializes a JSON string value to a URL.
33///
34/// # Arguments
35/// * `DeserializerInstance` - The serde deserializer instance
36///
37/// # Returns
38/// Result containing the parsed URL or deserialization error
39///
40/// # Behavior
41/// - Deserializes a string value
42/// - Parses the string as a URL
43/// - Returns parse error as custom deserialization error
44pub fn DeserializeURL<'de, D>(DeserializerInstance:D) -> Result<Url, D::Error>
45where
46 D: Deserializer<'de>, {
47 let string_value = String::deserialize(DeserializerInstance)?;
48
49 debug!("[URLDeserializer] Deserializing URL: {}", string_value);
50
51 Url::parse(&string_value).map_err(serde::de::Error::custom)
52}