r36

Crates.ior36
lib.rsr36
version0.1.2
created_at2025-03-21 08:51:27.618818+00
updated_at2025-03-21 08:51:53.009435+00
descriptionr36
homepagehttps://github.com/i18n-site/rust/tree/dev/r36
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1600313
size21,291
i18n.site (i18nsite)

documentation

README

r36

use num_traits::PrimInt;

pub fn e<T: PrimInt>(mut value: T) -> String {
  if value == T::zero() {
    return "0".to_string();
  }

  let radix = T::from(36).unwrap();
  let mut result = String::new();

  while value > T::zero() {
    let remainder = value % radix;
    let digit = remainder.to_u8().unwrap();

    let c = match digit {
      0..=9 => (b'0' + digit) as char,
      10..=35 => (b'A' + (digit - 10)) as char,
      _ => unreachable!(),
    };

    result.push(c);
    value = value / radix;
  }

  // 反转字符串,因为我们是从最低位开始构建的
  result.chars().rev().collect()
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt