Struct cor_args::JSONFileHandler
source · pub struct JSONFileHandler { /* private fields */ }Expand description
A handler for retrieving values from a specified JSON file.
This struct is responsible for handling requests by reading content from the file
specified in the underlying FileHandler, and then searching for a specific key
within the parsed JSON structure. If the key is not found in the JSON structure,
it delegates the request to the next handler (if provided).
Implementations§
source§impl JSONFileHandler
impl JSONFileHandler
sourcepub fn new<P>(file_path: P) -> Self
pub fn new<P>(file_path: P) -> Self
Creates a new JSONFileHandler with the specified file path and an optional next handler.
Arguments
file_path- The path to the JSON file from which values are to be retrieved.next- An optional next handler to which requests can be delegated if this handler can’t fulfill them.
pub fn next(self, handler: Box<dyn Handler>) -> Self
Trait Implementations§
source§impl Handler for JSONFileHandler
impl Handler for JSONFileHandler
source§fn handle_request(&self, key: &str) -> Option<String>
fn handle_request(&self, key: &str) -> Option<String>
Retrieves a value for the specified key from the JSON file.
This implementation attempts to read content from the file specified in the underlying FileHandler,
parses the content as JSON, and then searches for the specified key within the parsed JSON structure.
If the key is not found in the JSON structure, and if a next handler is provided, it delegates the request
to the next handler. If there’s no next handler, or if the key is not found in both the JSON structure
and the next handler, it returns None.
Arguments
key- The key for which the value needs to be retrieved from the JSON file.