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§
Sourcefn digits(self) -> Vec<u8> ⓘ
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]); // 負の数も絶対値で分解Sourcefn from_digits(digits: &[u8]) -> Self
fn from_digits(digits: &[u8]) -> Self
数字の列から数値を復元する (10進数)
§Example
use keta::Keta;
let nums = vec![1, 2, 3];
assert_eq!(u64::from_digits(&nums), 123);Sourcefn digit_product(self) -> u64
fn digit_product(self) -> u64
10進数での各桁の積を計算する
§Example
use keta::Keta;
assert_eq!(1234.digit_product(), 24);
assert_eq!(103.digit_product(), 0);Sourcefn digits_len(self) -> u32
fn digits_len(self) -> u32
Sourcefn reverse(self) -> Self
fn reverse(self) -> Self
数値の並びを反転させる (10進数)
§Example
use keta::Keta;
assert_eq!(123.reverse(), 321);
assert_eq!((-123).reverse(), -321); // 符号は維持Sourcefn is_palindrome(self) -> bool
fn is_palindrome(self) -> bool
回文数かどうか判定する (10進数)
§Example
use keta::Keta;
assert!(121.is_palindrome());
assert!(!123.is_palindrome());Sourcefn nth_digit(self, i: u32) -> Option<u8>
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);Sourcefn contains_digit(self, digit: u8) -> bool
fn contains_digit(self, digit: u8) -> bool
指定した数字(0-9)が含まれているか判定する (10進数)
§Example
use keta::Keta;
assert!(12345.contains_digit(3));
assert!(!12345.contains_digit(9));Sourcefn make_min(self) -> Self
fn make_min(self) -> Self
桁を並び替えてできる「最小の数値」を返す (10進数)
§Example
use keta::Keta;
assert_eq!(2026.make_min(), 226); // 0226 -> 226Sourcefn digits_radix(self, base: u32) -> Vec<u8> ⓘ
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]);Sourcefn from_digits_radix(digits: &[u8], base: u32) -> Self
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);Sourcefn digit_sum_radix(self, base: u32) -> u64
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);Sourcefn digit_product_radix(self, base: u32) -> u64
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);Sourcefn digits_len_radix(self, base: u32) -> u32
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);Sourcefn reverse_radix(self, base: u32) -> Self
fn reverse_radix(self, base: u32) -> Self
数値の並びを反転させる (n進数)
Sourcefn is_palindrome_radix(self, base: u32) -> bool
fn is_palindrome_radix(self, base: u32) -> bool
回文数かどうか判定する (n進数)
Sourcefn concat_radix(self, other: Self, base: u32) -> Self
fn concat_radix(self, other: Self, base: u32) -> Self
数値を結合する (n進数)
Sourcefn contains_digit_radix(self, digit: u8, base: u32) -> bool
fn contains_digit_radix(self, digit: u8, base: u32) -> bool
指定した数字が含まれているか判定する (n進数)
Sourcefn make_max_radix(self, base: u32) -> Self
fn make_max_radix(self, base: u32) -> Self
桁を並び替えてできる「最大の数値」を返す (n進数)
Sourcefn make_min_radix(self, base: u32) -> Self
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.