balanced_ternary/
conversions.rs1use crate::Digit;
14
15#[cfg(feature = "ternary-string")]
16use alloc::string::{String, ToString};
17
18#[cfg(feature = "ternary-string")]
19use crate::Ternary;
20
21impl From<char> for Digit {
22 fn from(value: char) -> Self {
23 Self::from_char(value)
24 }
25}
26
27impl From<i8> for Digit {
28 fn from(value: i8) -> Self {
29 Self::from_i8(value)
30 }
31}
32
33impl From<Digit> for char {
34 fn from(value: Digit) -> Self {
35 value.to_char()
36 }
37}
38
39impl From<Digit> for i8 {
40 fn from(value: Digit) -> Self {
41 value.to_i8()
42 }
43}
44
45#[cfg(feature = "ternary-string")]
46impl From<&str> for Ternary {
47 fn from(value: &str) -> Self {
48 Self::parse(value)
49 }
50}
51
52#[cfg(feature = "ternary-string")]
53impl From<String> for Ternary {
54 fn from(value: String) -> Self {
55 Self::from(value.as_str())
56 }
57}
58
59#[cfg(feature = "ternary-string")]
60impl From<i64> for Ternary {
61 fn from(value: i64) -> Self {
62 Self::from_dec(value)
63 }
64}
65
66#[cfg(feature = "ternary-string")]
67impl From<Ternary> for String {
68 fn from(value: Ternary) -> Self {
69 value.to_string()
70 }
71}
72
73#[cfg(feature = "ternary-string")]
74impl From<Ternary> for i64 {
75 fn from(value: Ternary) -> Self {
76 value.to_dec()
77 }
78}