Implement the Params struct in Rust, which will facilitate the management of query parameters for a web API. The struct should provide functionality for constructing query parameter strings and parsing them from strings.
Specific Requirements:
Struct Definition:
Create a struct named Params that contains the following fields:
query: Vec<(String, String)>: A vector of tuples representing query key-value pairs.
extra_fields: Vec<String>: A vector storing extra fields.
lang: Option<String>: An optional string for language settings.
limit: Option<u64>: An optional unsigned integer representing the limit on results.
offset: Option<u64>: An optional unsigned integer for pagination.
Methods Implementation:
Implement the following methods for the Params struct:
new() -> Params: A constructor that initializes Params with default values.
lang(self, l: impl Into<String>) -> Params: A method to set the language.
limit(self, l: u64) -> Params: A method to set the limit.
offset(self, o: u64) -> Params: A method to set the offset.
add_query<K, V>(self, key: K, value: V) -> Params: A method to add a query parameter.
with_extra_fields(self, fields: Vec<String>) -> Params: A method to set extra fields.
Display Implementation:
Implement the fmt::Display trait for Params to convert the struct to a query string format, ensuring the output follows the format specified in the tests.
String Parsing Implementation:
Implement the FromStr trait for Params, allowing the creation of a Params instance from a string that starts with a '?' followed by key=value pairs separated by '&'. Handle optional parameters and map them accordingly to the struct fields.
Conversion from Params to String:
Implement the From<Params> for String trait to allow direct conversion of Params instances into strings using the to_string method.
Directory Structure:
Place the implementation in the /app/ directory of your project.