//! rods - 一箇算籌化的 Rust 函式庫
//!
//! Copyright (c) 2026 Ghimist
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at https://mozilla.org/MPL/2.0/.

#[allow(dead_code)]
trait 弋: std::marker::Sized {
    fn 弋<業, 果>(self: Self, 式: 業) -> 果
    where
        業: std::ops::FnOnce(Self) -> 果,
    {
        式(self)
    }
}
impl<類: std::marker::Sized> 弋 for 類 {}

const 橫籌: [char; 10] = ['\u{30fb}', '𝍠', '𝍡', '𝍢', '𝍣', '𝍤', '𝍥', '𝍦', '𝍧', '𝍨'];
const 縱籌: [char; 10] = ['\u{3007}', '𝍩', '𝍪', '𝍫', '𝍬', '𝍭', '𝍮', '𝍯', '𝍰', '𝍱'];
pub fn 傳籌(入: impl AsRef<str>) -> String {
    入.as_ref()
        .chars()
        .enumerate()
        .map(|(干, 籌)| {
            if let Some(digit) = 籌.to_digit(10) {
                if 干 % 2 == 0 {
                    縱籌[digit as usize]
                } else {
                    橫籌[digit as usize]
                }
            } else {
                籌
            }
        })
        .collect()
}
pub use 傳籌 as rods; // 這樣在 main.rs 中就可以使用 rods::傳籌 來調用這個函數了

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_傳籌() {
        let result = "012345".弋(傳籌);
        println!("Hello, world! {}", result);
        println!("Hello, mars! {}", "299,792,458".弋(傳籌));
        // 你可以添加斷言，例如：
        // assert_eq!(result, "𝍩𝍠𝍪𝍡𝍫"); // 預期結果視實際字符而定
    }
}
