Browse Source

Minor version update (v0.1.5->v0.2.0)

Comment was added to Shared.lock_timeout to clarify it is seconds to
consider a dead lock.

Both the doc and example was updated to remove the derive Clone, that
is now entirely optional rather than required. (This also specifies when
this was made optional)
Apollo 4 months ago
parent
commit
18322411fe
5 changed files with 15 additions and 16 deletions
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 1 5
      README.md
  4. 2 1
      examples/doc_example.rs
  5. 10 8
      src/shared.rs

+ 1 - 1
Cargo.lock

@@ -115,7 +115,7 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
 
 [[package]]
 name = "shared"
-version = "0.1.4"
+version = "0.2.0"
 dependencies = [
  "tokio",
 ]

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "shared"
-version = "0.1.4"
+version = "0.2.0"
 edition = "2021"
 
 [dependencies]

+ 1 - 5
README.md

@@ -9,9 +9,5 @@ A Arc Mutex guarded data
 ```rust
 use shared::Shared;
 
-// Wrap your structure in Shared<S> via Shared::new(S)
+// Wrap your structure in Shared<S> via Shared::new(S) or Shared::with_timeout(S, deadlock_timeout)
 ```
-
-## Examples
-
-To run, say `doc_example` just `cargo run --example doc_example`.

+ 2 - 1
examples/doc_example.rs

@@ -1,6 +1,7 @@
 use shared::Shared;
 
-#[derive(Clone)]
+// #[derive(Clone)]
+// Clone is no longer needed as of v0.2.0
 struct Person {
     pub name: String,
     pub age: u16,

+ 10 - 8
src/shared.rs

@@ -5,6 +5,7 @@ use tokio::time::{timeout, Duration};
 // #[derive(Clone)] See issue #2
 pub struct Shared<T> {
     pub data: Arc<Mutex<T>>,
+    /// Number of seconds to consider a dead lock
     pub lock_timeout: u64,
 }
 
@@ -19,16 +20,17 @@ impl<T> Clone for Shared<T> {
 
 impl<T> Shared<T> {
     /// Creates a new Shared of data T
-    /// 
+    ///
     /// A lock timeout of 30 seconds is assigned by default (Use Shared::with_timeout to set the timeout yourself, or just edit the field as it is public)
     ///
     /// > Want to see a complete example, look at doc_example in the examples directory
-    /// 
+    ///
     /// Example:
     /// ```
     /// use shared::Shared;
     ///
-    /// #[derive(Clone)]
+    /// // #[derive(Clone)]
+    /// // Clone is no longer needed as of v0.2.0
     /// struct Person {
     ///     pub name: String,
     ///     pub age: u16
@@ -57,26 +59,26 @@ impl<T> Shared<T> {
     }
 
     /// Acquire lock
-    /// 
+    ///
     /// Will wait so many seconds as defined by lock_timeout (This will panic once the timeout is reached)
-    /// 
+    ///
     /// > Want to see a complete example, look at doc_example in the examples directory
     ///
     /// Using:
     /// ```
     /// // See Shared::new for creating a Shared<Person>
-    /// 
+    ///
     /// { // Direct access
     ///     let person = shared_data.lock().await;
     ///     println!("Person{{name: {}, age: {}}}", person.name, person.age);
     /// }
-    /// 
+    ///
     /// // Using it as a parameter
     /// async fn get_older(shared: Shared<Person>) {
     ///     let mut person = shared.lock().await;
     ///     person.age += 1;
     /// }
-    /// 
+    ///
     /// // Calling
     /// get_older(shared_data.clone()).await;
     /// ```