Problem
The add_record and edit_record methods in src/client.rs (lines 189 and 236) currently use #[allow(clippy::missing_panics_doc)] annotations because they call .expect("json object") on a serde_json::Value.
#[allow(clippy::missing_panics_doc)]
pub fn add_record(&self, params: &AddRecordParams) -> Result<Record> {
let mut json_params = serde_json::json!({
"domain": params.domain,
"type": params.record_type,
"name": params.name,
});
// Safe: json! macro always creates an object when given object syntax
let obj = json_params.as_object_mut().expect("json object");
// ...
}
While the comment explains that the expect() is safe because json! with object syntax always creates an object, this pattern:
- Requires the clippy allow annotation
- Has a theoretical panic point even if unreachable
Proposed Solution
Refactor to build the JSON object directly using serde_json::Map:
pub fn add_record(&self, params: &AddRecordParams) -> Result<Record> {
let mut obj = serde_json::Map::new();
obj.insert("domain".to_string(), serde_json::json!(params.domain));
obj.insert("type".to_string(), serde_json::json!(params.record_type));
obj.insert("name".to_string(), serde_json::json!(params.name));
if let Some(content) = ¶ms.content {
obj.insert("content".to_string(), serde_json::json!(content));
}
// ... rest of optional fields ...
self.request("add-record", serde_json::Value::Object(obj))
}
This approach:
- Eliminates the
expect() call entirely
- Removes the need for
#[allow(clippy::missing_panics_doc)]
- Makes the code slightly more explicit about what's happening
Files Affected
src/client.rs: add_record (line 189) and edit_record (line 236)
Problem
The
add_recordandedit_recordmethods insrc/client.rs(lines 189 and 236) currently use#[allow(clippy::missing_panics_doc)]annotations because they call.expect("json object")on aserde_json::Value.While the comment explains that the
expect()is safe becausejson!with object syntax always creates an object, this pattern:Proposed Solution
Refactor to build the JSON object directly using
serde_json::Map:This approach:
expect()call entirely#[allow(clippy::missing_panics_doc)]Files Affected
src/client.rs:add_record(line 189) andedit_record(line 236)