File: fibonacci.expanded.rs

package info (click to toggle)
rust-async-recursion 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 2
file content (18 lines) | stat: -rw-r--r-- 447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use async_recursion::async_recursion;
#[must_use]
fn fib(
    n: u32,
) -> ::core::pin::Pin<
    Box<dyn ::core::future::Future<Output = u64> + ::core::marker::Send>,
> {
    Box::pin(async move {
        match n {
            0 => {
                ::std::rt::begin_panic("zero is not a valid argument to fib()!");
            }
            1 | 2 => 1,
            3 => 2,
            _ => fib(n - 1).await + fib(n - 2).await,
        }
    })
}