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++.

22 lines 1.36 kB
{ "timestamp": "2025-08-02T14:34:17.833Z", "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```\nThis function now returns a `Result` type which can be either an `Ok` value (containing the result of the division operation), or an `Err` value (indicating that an error occurred). The string \"Cannot divide by zero\" is used as the payload for the error. This is idiomatic Rust and allows you to handle potential errors in a clear way.\n", "improvedCode": "fn 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}", "duration": 3959, "success": true, "qualityMetrics": { "hasCode": true, "hasResultType": true, "hasProperErrorHandling": true, "hasBorrowing": true, "score": 0.8461538461538461, "rawScore": 1.1, "maxScore": 1.3 }, "error": null }