(py: Python, data: impl std::ops::Deref<Target = data::Data>)
| 97 | } |
| 98 | |
| 99 | fn from_data(py: Python, data: impl std::ops::Deref<Target = data::Data>) -> PyResult<PyObject> { |
| 100 | match data.ty() { |
| 101 | data::DataType::Value(data::ValueType::Int) => { |
| 102 | let value: i64 = data::Get::get(&*data); |
| 103 | Ok(value.to_object(py)) |
| 104 | } |
| 105 | data::DataType::Value(data::ValueType::Float) => { |
| 106 | let value: f64 = data::Get::get(&*data); |
| 107 | Ok(value.to_object(py)) |
| 108 | } |
| 109 | data::DataType::Value(data::ValueType::Bool) => { |
| 110 | let value: bool = data::Get::get(&*data); |
| 111 | Ok(value.to_object(py)) |
| 112 | } |
| 113 | data::DataType::Value(data::ValueType::Byte) => { |
| 114 | let value: u8 = data::Get::get(&*data); |
| 115 | Ok(value.to_object(py)) |
| 116 | } |
| 117 | data::DataType::Collection(data::CollectionType::List(_)) => { |
| 118 | let list = data.clone(); |
| 119 | Py::new(py, PyList { inner: Some(list) }).map(|inner| inner.to_object(py)) |
| 120 | } |
| 121 | data::DataType::Collection(data::CollectionType::Map) => { |
| 122 | let map: &Map = data::GetRef::get_ref(&*data); |
| 123 | Py::new( |
| 124 | py, |
| 125 | PyMap { |
| 126 | inner: Some(map.to_owned()), |
| 127 | }, |
| 128 | ) |
| 129 | .map(|inner| inner.to_object(py)) |
| 130 | } |
| 131 | data::DataType::Collection(data::CollectionType::CowList) => { |
| 132 | let map: &CowList = data::GetRef::get_ref(&*data); |
| 133 | Py::new( |
| 134 | py, |
| 135 | PyCowList { |
| 136 | inner: Some(map.to_owned()), |
| 137 | }, |
| 138 | ) |
| 139 | .map(|inner| inner.to_object(py)) |
| 140 | } |
| 141 | data::DataType::Collection(data::CollectionType::CowMap) => { |
| 142 | let map: &CowMap = data::GetRef::get_ref(&*data); |
| 143 | Py::new( |
| 144 | py, |
| 145 | PyCowMap { |
| 146 | inner: Some(map.to_owned()), |
| 147 | }, |
| 148 | ) |
| 149 | .map(|inner| inner.to_object(py)) |
| 150 | } |
| 151 | _ => unimplemented!(), |
| 152 | } |
| 153 | } |
no test coverage detected