ソースを参照

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 ヶ月 前
コミット
18322411fe
5 ファイル変更15 行追加16 行削除
  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]]
 [[package]]
 name = "shared"
 name = "shared"
-version = "0.1.4"
+version = "0.2.0"
 dependencies = [
 dependencies = [
  "tokio",
  "tokio",
 ]
 ]

+ 1 - 1
Cargo.toml

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

+ 1 - 5
README.md

@@ -9,9 +9,5 @@ A Arc Mutex guarded data
 ```rust
 ```rust
 use shared::Shared;
 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;
 use shared::Shared;
 
 
-#[derive(Clone)]
+// #[derive(Clone)]
+// Clone is no longer needed as of v0.2.0
 struct Person {
 struct Person {
     pub name: String,
     pub name: String,
     pub age: u16,
     pub age: u16,

+ 10 - 8
src/shared.rs

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