chore: extract arbitrary
into its own crate arbitrary-value
This commit is contained in:
51
Cargo.toml
51
Cargo.toml
@@ -1,45 +1,16 @@
|
||||
[package]
|
||||
name = "smart-home-in-rust-with-home-assistant"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
[workspace]
|
||||
members = [
|
||||
"arbitrary-value",
|
||||
resolver = "2"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
name = "smart_home_in_rust_with_home_assistant"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
[workspace.dependencies]
|
||||
backoff = "0.4.0"
|
||||
chrono = "0.4.40"
|
||||
chrono-tz = "0.10.1"
|
||||
derive_more = { version = "2.0.1", features = [
|
||||
"display",
|
||||
"from",
|
||||
"into",
|
||||
"try_from",
|
||||
"try_into",
|
||||
] }
|
||||
ijson = "0.1.4"
|
||||
itertools = "0.14.0"
|
||||
pyo3 = { version = "0.24.0", features = [
|
||||
"auto-initialize",
|
||||
"chrono",
|
||||
"chrono-tz",
|
||||
] }
|
||||
pyo3-async-runtimes = { version = "0.24.0", features = ["tokio-runtime"] }
|
||||
serde_json = "1.0.140"
|
||||
shadow-rs = { version = "1.0.1", default-features = false }
|
||||
deranged = "0.4.1"
|
||||
derive_more = "2.0.1"
|
||||
snafu = "0.8.5"
|
||||
strum = { version = "0.27.1", features = ["derive"] }
|
||||
tokio = { version = "1.32.0", features = [
|
||||
"rt",
|
||||
"rt-multi-thread",
|
||||
"sync",
|
||||
"time",
|
||||
] }
|
||||
tokio = "1.32.0"
|
||||
pyo3 = "0.24.0"
|
||||
pyo3-async-runtimes = "0.24.0"
|
||||
tracing = "0.1.37"
|
||||
tracing-appender = "0.2.3"
|
||||
tracing-subscriber = "0.3.17"
|
||||
ulid = "1.2.0"
|
||||
|
||||
[build-dependencies]
|
||||
shadow-rs = "1.0.1"
|
||||
|
17
arbitrary-value/Cargo.toml
Normal file
17
arbitrary-value/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "arbitrary-value"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
pyo3 = ["dep:pyo3"]
|
||||
|
||||
[dependencies]
|
||||
chrono = { workspace = true }
|
||||
chrono-tz = { workspace = true }
|
||||
derive_more = { workspace = true }
|
||||
ijson = "0.1.4"
|
||||
itertools = "0.14.0"
|
||||
snafu = { workspace = true }
|
||||
|
||||
pyo3 = { workspace = true, optional = true, features = ["chrono", "chrono-tz"] }
|
@@ -1,6 +1,7 @@
|
||||
use chrono::DateTime;
|
||||
use chrono_tz::Tz;
|
||||
use ijson::{IArray, INumber, IObject, IString, IValue};
|
||||
#[cfg(feature = "pyo3")]
|
||||
use pyo3::{
|
||||
exceptions::{PyTypeError, PyValueError},
|
||||
prelude::*,
|
||||
@@ -71,6 +72,7 @@ impl From<Arbitrary> for IValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pyo3")]
|
||||
impl<'py> FromPyObject<'py> for Arbitrary {
|
||||
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
|
||||
if let Ok(map_key) = ob.extract::<MapKey>() {
|
||||
@@ -91,6 +93,7 @@ impl<'py> FromPyObject<'py> for Arbitrary {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pyo3")]
|
||||
impl<'py> IntoPyObject<'py> for Arbitrary {
|
||||
type Target = PyAny;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use pyo3::IntoPyObject;
|
||||
use snafu::Snafu;
|
||||
|
||||
#[derive(Debug, Clone, derive_more::Into, IntoPyObject)]
|
||||
#[cfg_attr(feature = "pyo3", derive(pyo3::IntoPyObject))]
|
||||
#[derive(Debug, Clone, derive_more::Into)]
|
||||
pub struct FiniteF64(f64);
|
||||
|
||||
#[derive(Debug, Snafu)]
|
@@ -2,3 +2,5 @@ pub mod arbitrary;
|
||||
pub mod finite_f64;
|
||||
pub mod map;
|
||||
pub mod map_key;
|
||||
|
||||
pub use arbitrary::*;
|
7
arbitrary-value/src/map.rs
Normal file
7
arbitrary-value/src/map.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::{arbitrary::Arbitrary, map_key::MapKey};
|
||||
|
||||
#[cfg_attr(feature = "pyo3", derive(pyo3::FromPyObject, pyo3::IntoPyObject))]
|
||||
#[derive(Debug, Clone, Default, derive_more::From, derive_more::Into)]
|
||||
pub struct Map(pub BTreeMap<MapKey, Arbitrary>);
|
@@ -4,6 +4,7 @@ use chrono::DateTime;
|
||||
use chrono_tz::Tz;
|
||||
use ijson::IString;
|
||||
use itertools::Itertools;
|
||||
#[cfg(feature = "pyo3")]
|
||||
use pyo3::{
|
||||
exceptions::PyTypeError,
|
||||
prelude::*,
|
||||
@@ -41,6 +42,7 @@ impl Display for MapKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pyo3")]
|
||||
impl<'py> FromPyObject<'py> for MapKey {
|
||||
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
|
||||
if let Ok(_none) = ob.downcast::<PyNone>() {
|
||||
@@ -62,6 +64,7 @@ impl<'py> FromPyObject<'py> for MapKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pyo3")]
|
||||
impl<'py> IntoPyObject<'py> for MapKey {
|
||||
type Target = PyAny;
|
||||
|
@@ -1,16 +0,0 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
use super::{arbitrary::Arbitrary, map_key::MapKey};
|
||||
|
||||
#[derive(Debug, Clone, Default, derive_more::From, derive_more::Into, IntoPyObject)]
|
||||
pub struct Map(pub BTreeMap<MapKey, Arbitrary>);
|
||||
|
||||
impl<'py> FromPyObject<'py> for Map {
|
||||
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
|
||||
let inner = ob.extract()?;
|
||||
|
||||
Ok(Self(inner))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user