Browse Source

Separated Data and Shared (v0.1.3)

Apollo 4 months ago
parent
commit
09ff6040e0
4 changed files with 40 additions and 122 deletions
  1. 1 103
      Cargo.lock
  2. 17 4
      Cargo.toml
  3. 18 15
      src/data.rs
  4. 4 0
      src/lib.rs

+ 1 - 103
Cargo.lock

@@ -17,18 +17,6 @@ version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
 
-[[package]]
-name = "anyhow"
-version = "1.0.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
-
-[[package]]
-name = "autocfg"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
-
 [[package]]
 name = "backtrace"
 version = "0.3.73"
@@ -71,12 +59,6 @@ version = "0.2.158"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
 
-[[package]]
-name = "libm"
-version = "0.2.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
-
 [[package]]
 name = "memchr"
 version = "2.7.4"
@@ -92,80 +74,6 @@ dependencies = [
  "adler",
 ]
 
-[[package]]
-name = "num"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
-dependencies = [
- "num-bigint",
- "num-complex",
- "num-integer",
- "num-iter",
- "num-rational",
- "num-traits",
-]
-
-[[package]]
-name = "num-bigint"
-version = "0.4.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
-dependencies = [
- "num-integer",
- "num-traits",
-]
-
-[[package]]
-name = "num-complex"
-version = "0.4.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
-dependencies = [
- "num-traits",
-]
-
-[[package]]
-name = "num-integer"
-version = "0.1.46"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
-dependencies = [
- "num-traits",
-]
-
-[[package]]
-name = "num-iter"
-version = "0.1.45"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
-dependencies = [
- "autocfg",
- "num-integer",
- "num-traits",
-]
-
-[[package]]
-name = "num-rational"
-version = "0.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
-dependencies = [
- "num-bigint",
- "num-integer",
- "num-traits",
-]
-
-[[package]]
-name = "num-traits"
-version = "0.2.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
-dependencies = [
- "autocfg",
- "libm",
-]
-
 [[package]]
 name = "object"
 version = "0.36.4"
@@ -181,15 +89,6 @@ version = "0.2.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
 
-[[package]]
-name = "point"
-version = "0.1.5"
-source = "git+https://git.red-green.com/david/point#5776731e72b6f2dbbdaf887236b1622cc3b3c6b6"
-dependencies = [
- "anyhow",
- "num",
-]
-
 [[package]]
 name = "proc-macro2"
 version = "1.0.86"
@@ -236,9 +135,8 @@ dependencies = [
 
 [[package]]
 name = "shared"
-version = "0.1.2"
+version = "0.1.3"
 dependencies = [
- "point",
  "serde",
  "tokio",
 ]

+ 17 - 4
Cargo.toml

@@ -1,13 +1,26 @@
 [package]
 name = "shared"
-version = "0.1.2"
+version = "0.1.3"
 edition = "2021"
 
 [features]
-cast_into = []
-serde = ["dep:serde"]
+shared = ["dep:tokio"]
+data = []
+cast_into = ["data"]
+serde = ["dep:serde", "data"]
 
 [dependencies]
-tokio = { version = "1.40.0", features = ["macros", "rt", "rt-multi-thread", "sync", "time"] }
+tokio = { version = "1.40.0", features = ["macros", "rt", "rt-multi-thread", "sync", "time"], optional = true}
 serde = { version = "1.0", features = ["derive"], optional = true}
 
+[[example]]
+name = "collection_data_example"
+required-features = ["data"]
+
+[[example]]
+name = "data_example"
+required-features = ["data"]
+
+[[example]]
+name = "doc_example"
+required-features = ["shared"]

+ 18 - 15
src/data.rs

@@ -1,5 +1,6 @@
 use std::{collections::HashMap, fmt::Display, slice::{SliceIndex, Iter, IterMut}};
 
+#[cfg(feature = "shared")]
 use crate::Shared;
 
 #[cfg(not(feature = "serde"))]
@@ -520,8 +521,10 @@ impl TryInto<HashMap<String, Data>> for Data {
     }
 }
 
+
 // To cast Data into `Shared<Data>`
 // (Because we're still in the crate, we can do this)
+#[cfg(feature = "shared")]
 impl From<Data> for Shared<Data> {
     fn from(v: Data) -> Self {
         Shared::new(v)
@@ -546,7 +549,7 @@ impl Data {
         Self::Map(HashMap::with_capacity(cap))
     }
     /// Is Data not the variant None
-    /// 
+    ///
     /// This is useful for using Data similar to a Option
     pub fn is_some(&self) -> bool {
         !matches!(self, Self::None)
@@ -560,19 +563,19 @@ impl Data {
         matches!(self, Self::String(_))
     }
     /// Is Data a signed/unsigned integer or float
-    /// 
+    ///
     /// JSON Number's can hold both a whole number (i.e. signed/unsigned integers) and floats
     pub fn is_number(&self) -> bool {
         matches!(self, Self::I8(_) | Self::I16(_) | Self::I32(_) | Self::I64(_) | Self::I128(_) | Self::U8(_) | Self::U16(_) | Self::U32(_) | Self::U64(_) | Self::U128(_) | Self::F32(_) | Self::F64(_))
     }
     /// Is Data a signed integer (Regardless of bits)
-    /// 
+    ///
     /// i.e. i8, i16, i32, i64, i128 or neither
     pub fn is_int(&self) -> bool {
         matches!(self, Self::I8(_) | Self::I16(_) | Self::I32(_) | Self::I64(_) | Self::I128(_))
     }
     /// Is Data a unsigned integer (Regardless of bits)
-    /// 
+    ///
     /// i.e. u8, u16, u32, u64, or u128 or neither
     pub fn is_uint(&self) -> bool {
         matches!(self, Self::U8(_) | Self::U16(_) | Self::U32(_) | Self::U64(_) | Self::U128(_))
@@ -582,7 +585,7 @@ impl Data {
         matches!(self, Self::F32(_) | Self::F64(_))
     }
     /// Does Data contain something that holds other Data
-    /// 
+    ///
     /// `Vec<Data>` or `HashMap<String, Data>` are examples of "nested" Data
     pub fn is_nested(&self) -> bool {
         matches!(self, Self::Vec(_) | Self::Map(_))
@@ -596,7 +599,7 @@ impl Data {
         matches!(self, Self::Map(_))
     }
     /// Push a value into the Data
-    /// 
+    ///
     /// Must be a Vec or no-op
     pub fn vec_push(&mut self, v: Data) {
         if let Self::Vec(vec) = self {
@@ -604,7 +607,7 @@ impl Data {
         }
     }
     /// Assigns/Reassigns a key the value into the Data
-    /// 
+    ///
     /// Must be a Map or no-op
     pub fn map_insert(&mut self, k: String, v: Data) {
         if let Self::Map(hm) = self {
@@ -612,7 +615,7 @@ impl Data {
         }
     }
     /// Obtains the length of String, Vec or Map
-    /// 
+    ///
     /// All other variants of Data will return 0
     pub fn len(&self) -> usize {
         match self {
@@ -623,7 +626,7 @@ impl Data {
         }
     }
     /// Obtains the capacity of Vec or Map
-    /// 
+    ///
     /// All other variants of Data return 0
     pub fn capacity(&self) -> usize {
         match self {
@@ -633,7 +636,7 @@ impl Data {
         }
     }
     /// Reserve {additional} in a Vec or Map
-    /// 
+    ///
     /// This no-op's if the Data variants are not Vec or Map
     pub fn reserve(&mut self, additional: usize) {
         match self {
@@ -670,7 +673,7 @@ impl Data {
         }
     }
     /// Removes the last item in the Vec, see [Vec::pop]
-    /// 
+    ///
     /// This will return None also if the Data isn't a Vec
     pub fn vec_pop(&mut self) -> Option<Data> {
         match self {
@@ -738,7 +741,7 @@ impl Data {
             _ => None,
         }
     }
-    /// Gets like [Data::vec_get] except as mutable 
+    /// Gets like [Data::vec_get] except as mutable
     pub fn vec_get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
     where
         I: SliceIndex<[Data]>,
@@ -791,7 +794,7 @@ impl Data {
         if let Self::Vec(v) = self { v.reverse() }
     }
     /// Attempts to form an iterator for Vec
-    /// 
+    ///
     /// This can fail if Data isn't a Vec
     pub fn vec_iter(&self) -> Option<Iter<'_, Data>> {
         match self {
@@ -800,7 +803,7 @@ impl Data {
         }
     }
     /// Attempts to form a mutable iterator for Vec
-    /// 
+    ///
     /// This can fail if Data isn't a Vec
     pub fn vec_iter_mut(&mut self) -> Option<IterMut<'_, Data>> {
         match self {
@@ -809,7 +812,7 @@ impl Data {
         }
     }
     /// This will determine the size of signed or unsigned integers and floats
-    /// 
+    ///
     /// i.e. i32 is 32, u64 is 64, f32 is 32, u128 is 128 (Meanwhile, anything else is 0, String is 0, Bool is 0, etc.)
     pub fn bit_variant(&self) -> u8 {
         match self {

+ 4 - 0
src/lib.rs

@@ -1,6 +1,10 @@
 
+#[cfg(feature = "shared")]
 mod shared;
+#[cfg(feature = "shared")]
 pub use shared::Shared;
 
+#[cfg(feature = "data")]
 mod data;
+#[cfg(feature = "data")]
 pub use data::Data;