Skip to content

Commit

Permalink
fix: fix rust to python conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tardyp committed Jun 8, 2024
1 parent 37379eb commit e5ac04c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn map_to_py(dict: &RsMap) -> HashMap<String, Value> {
#[derive(Debug, Clone, FromPyObject)]
pub enum Value {
String(String),
Array(Vec<String>),
Array(Vec<Value>),
Boolean(bool),
Map(HashMap<String, Value>),
Ident(String),
Expand Down Expand Up @@ -102,16 +102,20 @@ impl BluePrint {
.collect()
}
}
impl From<&RsValue> for Value {
fn from(v: &RsValue) -> Self {
match v {
RsValue::String(s) => Value::String(s.to_owned()),
RsValue::Array(a) => Value::Array(a.iter().map(|x| Value::from(x)).collect()),
RsValue::Boolean(b) => Value::Boolean(b.to_owned()),
RsValue::Map(d) => Value::Map(map_to_py(&d)),
RsValue::Ident(i) => Value::Ident(i.to_owned()),
}
}
}
fn value_to_pyvalue(t: (&String, &RsValue)) -> (String, Value) {
let (k, v) = t;
let value = match v {
RsValue::String(s) => Value::String(s.to_owned()),
RsValue::Array(a) => Value::Array(a.to_owned()),
RsValue::Boolean(b) => Value::Boolean(b.to_owned()),
RsValue::Map(d) => Value::Map(map_to_py(&d)),
RsValue::Ident(i) => Value::Ident(i.to_owned()),
};
(k.to_owned(), value)
(k.to_owned(), v.into())
}
#[pymodule]
fn android_bp(_py: Python, m: &PyModule) -> PyResult<()> {
Expand Down

0 comments on commit e5ac04c

Please sign in to comment.