UNPKG

codebridge-ai

Version:

Complete fullstack AI coding platform with AST-based code integration and local LLM support. Now with comprehensive web technology support (HTML/CSS/JS) plus JavaScript, Python, Rust, and C++.

20 lines 1.55 kB
{ "timestamp": "2025-08-02T16:15:51.948Z", "model": "deepseek-coder:6.7b", "language": "rust", "scenario": "basic-safety", "task": "Add Result type for safe division and handle zero", "originalCode": "fn divide(a: f64, b: f64) -> f64 {\n a / b\n}", "rawResponse": "Here is your updated function in Rust, using the `Result` enum to handle potential errors (division by zero):\n\n```rust\nfn divide(a: f64, b: f64) -> Result<f64, &'static str> {\n if b == 0.0 {\n Err(\"Cannot divide by zero\")\n } else {\n Ok(a / b)\n }\n}\n```\n\nYou can use this function in a way that is safe from division by zero:\n\n```rust\nfn main() {\n match divide(10.0, 2.0) {\n Ok(result) => printlnrlnln\"Result: {}\", result),\n Err(error_message) => printlnrlnln\"Error: {}\", error_message),\n }\n}\n```\n\nIn this way, if the second argument to `divide` is zero, it will return an instance of `Err` with a string message. If not, it returns an instance of `Ok` containing the result of division. This allows you to handle potential errors in a safe and idiomatic way in Rust.\n", "improvedCode": "fn main() {\n match divide(10.0, 2.0) {\n Ok(result) => printlnrlnln\"Result: {}\", result),\n Err(error_message) => printlnrlnln\"Error: {}\", error_message),\n }\n}", "duration": 6187, "success": false, "qualityMetrics": { "hasCode": true, "hasProperErrorHandling": true, "score": 0.3846153846153846, "rawScore": 0.5, "maxScore": 1.3 }, "error": null }