/rust/registry/src/index.crates.io-1949cf8c6b5b557f/lexpr-0.2.7/src/value/from.rs
Line | Count | Source |
1 | | use std::borrow::Cow; |
2 | | |
3 | | use crate::{Cons, Number, Value}; |
4 | | |
5 | | macro_rules! impl_from_number { |
6 | | ( |
7 | | $($ty:ty),* |
8 | | ) => { |
9 | | $( |
10 | | impl From<$ty> for Value { |
11 | | #[inline] |
12 | 0 | fn from(n: $ty) -> Self { |
13 | 0 | Value::Number(Number::from(n)) |
14 | 0 | } Unexecuted instantiation: <lexpr::value::Value as core::convert::From<u64>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<i64>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<f64>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<u8>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<u16>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<u32>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<u64>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<i8>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<i16>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<i32>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<i64>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<f32>>::from Unexecuted instantiation: <lexpr::value::Value as core::convert::From<f64>>::from |
15 | | } |
16 | | )* |
17 | | }; |
18 | | } |
19 | | |
20 | | impl_from_number!(u8, u16, u32, u64, i8, i16, i32, i64, f32, f64); |
21 | | |
22 | | impl From<char> for Value { |
23 | | #[inline] |
24 | 0 | fn from(c: char) -> Self { |
25 | 0 | Value::Char(c) |
26 | 0 | } |
27 | | } |
28 | | |
29 | | impl From<&str> for Value { |
30 | | #[inline] |
31 | 0 | fn from(s: &str) -> Self { |
32 | 0 | Value::String(s.into()) |
33 | 0 | } |
34 | | } |
35 | | |
36 | | impl<'a> From<Cow<'a, str>> for Value { |
37 | | #[inline] |
38 | 0 | fn from(s: Cow<'a, str>) -> Self { |
39 | 0 | Value::from(s.as_ref()) |
40 | 0 | } |
41 | | } |
42 | | |
43 | | impl From<Box<str>> for Value { |
44 | | #[inline] |
45 | 0 | fn from(s: Box<str>) -> Self { |
46 | 0 | Value::String(s) |
47 | 0 | } |
48 | | } |
49 | | |
50 | | impl From<String> for Value { |
51 | | #[inline] |
52 | 0 | fn from(s: String) -> Self { |
53 | 0 | Value::String(s.into_boxed_str()) |
54 | 0 | } |
55 | | } |
56 | | |
57 | | impl From<bool> for Value { |
58 | | #[inline] |
59 | 0 | fn from(v: bool) -> Self { |
60 | 0 | Value::Bool(v) |
61 | 0 | } |
62 | | } |
63 | | |
64 | | impl From<&[u8]> for Value { |
65 | | #[inline] |
66 | 0 | fn from(bytes: &[u8]) -> Self { |
67 | 0 | Value::Bytes(bytes.into()) |
68 | 0 | } |
69 | | } |
70 | | |
71 | | impl From<Box<[u8]>> for Value { |
72 | | #[inline] |
73 | 0 | fn from(bytes: Box<[u8]>) -> Self { |
74 | 0 | Value::Bytes(bytes) |
75 | 0 | } |
76 | | } |
77 | | |
78 | | impl From<Vec<u8>> for Value { |
79 | | #[inline] |
80 | 0 | fn from(bytes: Vec<u8>) -> Self { |
81 | 0 | Value::Bytes(bytes.into_boxed_slice()) |
82 | 0 | } |
83 | | } |
84 | | |
85 | | impl From<Number> for Value { |
86 | 0 | fn from(n: Number) -> Self { |
87 | 0 | Value::Number(n) |
88 | 0 | } |
89 | | } |
90 | | |
91 | | impl<T, U> From<(T, U)> for Value |
92 | | where |
93 | | T: Into<Value>, |
94 | | U: Into<Value>, |
95 | | { |
96 | 0 | fn from((car, cdr): (T, U)) -> Self { |
97 | 0 | Value::Cons(Cons::new(car, cdr)) |
98 | 0 | } |
99 | | } |
100 | | |
101 | | impl From<Cons> for Value { |
102 | 0 | fn from(pair: Cons) -> Self { |
103 | 0 | Value::Cons(pair) |
104 | 0 | } |
105 | | } |
106 | | |
107 | | impl From<Vec<Value>> for Value { |
108 | 0 | fn from(elts: Vec<Value>) -> Self { |
109 | 0 | Value::Vector(elts.into()) |
110 | 0 | } |
111 | | } |
112 | | |
113 | | impl From<Box<[Value]>> for Value { |
114 | 0 | fn from(elts: Box<[Value]>) -> Self { |
115 | 0 | Value::Vector(elts) |
116 | 0 | } |
117 | | } |