Skip to content

Instantly share code, notes, and snippets.

@isaacharrisholt
Created May 29, 2023 18:46
Show Gist options
  • Save isaacharrisholt/4aa158b7bc7e8787d221baeee55dbea9 to your computer and use it in GitHub Desktop.
Save isaacharrisholt/4aa158b7bc7e8787d221baeee55dbea9 to your computer and use it in GitHub Desktop.
Fibonacci - Rust implementation
use pyo3::prelude::*;
/// Calculate the nth Fibonacci number.
#[pyfunction]
fn fib(n: u32) -> u32 {
if n <= 1 {
return n;
}
fib(n - 1) + fib(n - 2)
}
/// Fast Fibonacci number calculation.
#[pymodule]
fn fibbers(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(fib, m)?)?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment