Keta

Trait Keta 

Source
pub trait Keta: Copy {
Show 24 methods // Required methods fn digits(self) -> Vec<u8> ; fn from_digits(digits: &[u8]) -> Self; fn digit_sum(self) -> u64; fn digit_product(self) -> u64; fn digits_len(self) -> u32; fn reverse(self) -> Self; fn is_palindrome(self) -> bool; fn nth_digit(self, i: u32) -> Option<u8>; fn concat(self, other: Self) -> Self; fn contains_digit(self, digit: u8) -> bool; fn make_max(self) -> Self; fn make_min(self) -> Self; fn digits_radix(self, base: u32) -> Vec<u8> ; fn from_digits_radix(digits: &[u8], base: u32) -> Self; fn digit_sum_radix(self, base: u32) -> u64; fn digit_product_radix(self, base: u32) -> u64; fn digits_len_radix(self, base: u32) -> u32; fn reverse_radix(self, base: u32) -> Self; fn is_palindrome_radix(self, base: u32) -> bool; fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>; fn concat_radix(self, other: Self, base: u32) -> Self; fn contains_digit_radix(self, digit: u8, base: u32) -> bool; fn make_max_radix(self, base: u32) -> Self; fn make_min_radix(self, base: u32) -> Self;
}

Required Methods§

Source

fn digits(self) -> Vec<u8>

10進数で各桁の数字(u8)のベクタに分解する

§Example
use keta::Keta;
assert_eq!(12345.digits(), vec![1, 2, 3, 4, 5]);
assert_eq!((-12345).digits(), vec![1, 2, 3, 4, 5]); // 負の数も絶対値で分解
Source

fn from_digits(digits: &[u8]) -> Self

数字の列から数値を復元する (10進数)

§Example
use keta::Keta;
let nums = vec![1, 2, 3];
assert_eq!(u64::from_digits(&nums), 123);
Source

fn digit_sum(self) -> u64

10進数での各桁の和を計算する

§Example
use keta::Keta;
assert_eq!(123.digit_sum(), 6);
Source

fn digit_product(self) -> u64

10進数での各桁の積を計算する

§Example
use keta::Keta;
assert_eq!(1234.digit_product(), 24);
assert_eq!(103.digit_product(), 0);
Source

fn digits_len(self) -> u32

10進数での桁数を返す (ilog10を使用するため高速)

§Example
use keta::Keta;
assert_eq!(100.digits_len(), 3);
Source

fn reverse(self) -> Self

数値の並びを反転させる (10進数)

§Example
use keta::Keta;
assert_eq!(123.reverse(), 321);
assert_eq!((-123).reverse(), -321); // 符号は維持
Source

fn is_palindrome(self) -> bool

回文数かどうか判定する (10進数)

§Example
use keta::Keta;
assert!(121.is_palindrome());
assert!(!123.is_palindrome());
Source

fn nth_digit(self, i: u32) -> Option<u8>

上からi番目の桁を取得する (10進数, 0-indexed)

§Example
use keta::Keta;
assert_eq!(12345.nth_digit(0), Some(1));
assert_eq!(12345.nth_digit(4), Some(5));
assert_eq!(12345.nth_digit(100), None);
Source

fn concat(self, other: Self) -> Self

数値を結合する (10進数)

§Example
use keta::Keta;
assert_eq!(12.concat(34), 1234);
Source

fn contains_digit(self, digit: u8) -> bool

指定した数字(0-9)が含まれているか判定する (10進数)

§Example
use keta::Keta;
assert!(12345.contains_digit(3));
assert!(!12345.contains_digit(9));
Source

fn make_max(self) -> Self

桁を並び替えてできる「最大の数値」を返す (10進数)

§Example
use keta::Keta;
assert_eq!(2026.make_max(), 6220);
Source

fn make_min(self) -> Self

桁を並び替えてできる「最小の数値」を返す (10進数)

§Example
use keta::Keta;
assert_eq!(2026.make_min(), 226); // 0226 -> 226
Source

fn digits_radix(self, base: u32) -> Vec<u8>

n進数で各桁の数字(u8)のベクタに分解する

§Example
use keta::Keta;
// 6 (10進数) -> 110 (2進数)
assert_eq!(6.digits_radix(2), vec![1, 1, 0]);
// 255 (10進数) -> FF (16進数) -> [15, 15]
assert_eq!(255.digits_radix(16), vec![15, 15]);
Source

fn from_digits_radix(digits: &[u8], base: u32) -> Self

n進数の数字列から数値を復元する

§Example
use keta::Keta;
// 110 (2進数) -> 6 (10進数)
assert_eq!(u64::from_digits_radix(&[1, 1, 0], 2), 6);
Source

fn digit_sum_radix(self, base: u32) -> u64

n進数での各桁の和を計算する

§Example
use keta::Keta;
// 6 (10進数) -> 110 (2進数) -> 1+1+0 = 2
assert_eq!(6.digit_sum_radix(2), 2);
Source

fn digit_product_radix(self, base: u32) -> u64

n進数での各桁の積を計算する

§Example
use keta::Keta;
// 7 (10進数) -> 111 (2進数) -> 1*1*1 = 1
assert_eq!(7.digit_product_radix(2), 1);
Source

fn digits_len_radix(self, base: u32) -> u32

n進数での桁数を返す

§Example
use keta::Keta;
// 16 (10進数) -> 10000 (2進数) -> 5桁
assert_eq!(16.digits_len_radix(2), 5);
Source

fn reverse_radix(self, base: u32) -> Self

数値の並びを反転させる (n進数)

Source

fn is_palindrome_radix(self, base: u32) -> bool

回文数かどうか判定する (n進数)

Source

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

上からi番目の桁を取得する (n進数, 0-indexed)

Source

fn concat_radix(self, other: Self, base: u32) -> Self

数値を結合する (n進数)

Source

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

指定した数字が含まれているか判定する (n進数)

Source

fn make_max_radix(self, base: u32) -> Self

桁を並び替えてできる「最大の数値」を返す (n進数)

Source

fn make_min_radix(self, base: u32) -> Self

桁を並び替えてできる「最小の数値」を返す (n進数)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Keta for i8

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for i16

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for i32

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for i64

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for i128

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for isize

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for u8

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for u16

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for u32

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for u64

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for u128

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Source§

impl Keta for usize

Source§

fn digits_radix(self, base: u32) -> Vec<u8>

Source§

fn from_digits_radix(digits: &[u8], base: u32) -> Self

Source§

fn digit_sum_radix(self, base: u32) -> u64

Source§

fn digit_product_radix(self, base: u32) -> u64

Source§

fn digits_len_radix(self, base: u32) -> u32

Source§

fn reverse_radix(self, base: u32) -> Self

Source§

fn is_palindrome_radix(self, base: u32) -> bool

Source§

fn nth_digit_radix(self, i: u32, base: u32) -> Option<u8>

Source§

fn concat_radix(self, other: Self, base: u32) -> Self

Source§

fn contains_digit_radix(self, digit: u8, base: u32) -> bool

Source§

fn make_max_radix(self, base: u32) -> Self

Source§

fn make_min_radix(self, base: u32) -> Self

Source§

fn digits(self) -> Vec<u8>

Source§

fn from_digits(digits: &[u8]) -> Self

Source§

fn digit_sum(self) -> u64

Source§

fn digit_product(self) -> u64

Source§

fn digits_len(self) -> u32

Source§

fn reverse(self) -> Self

Source§

fn is_palindrome(self) -> bool

Source§

fn nth_digit(self, i: u32) -> Option<u8>

Source§

fn concat(self, other: Self) -> Self

Source§

fn contains_digit(self, digit: u8) -> bool

Source§

fn make_max(self) -> Self

Source§

fn make_min(self) -> Self

Implementors§