Skip to content

Commit 4eebdf4

Browse files
committed
prepare actix-utils release 3.0.0-beta.3
1 parent b09e7cd commit 4eebdf4

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

actix-utils/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changes
22

33
## Unreleased - 2021-xx-xx
4+
5+
6+
## 3.0.0-beta.3 - 2021-04-01
47
* Moved `mpsc` to own crate `local-channel`. [#301]
58
* Moved `task::LocalWaker` to own crate `local-waker`. [#301]
69
* Remove `timeout` module. [#301]

actix-utils/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[package]
22
name = "actix-utils"
3-
version = "3.0.0-beta.2"
4-
authors = ["Nikolay Kim <[email protected]>"]
5-
description = "Various network related services and utilities for the Actix ecosystem"
3+
version = "3.0.0-beta.3"
4+
authors = [
5+
"Nikolay Kim <[email protected]>",
6+
"Rob Ede <[email protected]>",
7+
]
8+
description = "Utilities for the Actix ecosystem"
69
keywords = ["network", "framework", "async", "futures"]
7-
homepage = "https://actix.rs"
810
repository = "https://github.com/actix/actix-net.git"
9-
documentation = "https://docs.rs/actix-utils"
1011
categories = ["network-programming", "asynchronous"]
1112
license = "MIT OR Apache-2.0"
1213
edition = "2018"

actix-utils/src/counter.rs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
//! Task-notifying counter.
22
3-
use core::{cell::Cell, task};
3+
use core::{cell::Cell, fmt, task};
44
use std::rc::Rc;
55

66
use local_waker::LocalWaker;
77

8-
#[derive(Clone)]
98
/// Simple counter with ability to notify task on reaching specific number
109
///
1110
/// Counter could be cloned, total n-count is shared across all clones.
11+
#[derive(Debug, Clone)]
1212
pub struct Counter(Rc<CounterInner>);
1313

14-
struct CounterInner {
15-
count: Cell<usize>,
16-
capacity: usize,
17-
task: LocalWaker,
18-
}
19-
2014
impl Counter {
21-
/// Create `Counter` instance and set max value.
15+
/// Create `Counter` instance with max value.
2216
pub fn new(capacity: usize) -> Self {
2317
Counter(Rc::new(CounterInner {
2418
capacity,
@@ -27,38 +21,26 @@ impl Counter {
2721
}))
2822
}
2923

30-
/// Get counter guard.
24+
/// Create new counter guard, incrementing the counter.
3125
pub fn get(&self) -> CounterGuard {
3226
CounterGuard::new(self.0.clone())
3327
}
3428

35-
/// Check if counter is not at capacity. If counter at capacity
36-
/// it registers notification for current task.
29+
/// Notify current task and return true if counter is at capacity.
3730
pub fn available(&self, cx: &mut task::Context<'_>) -> bool {
3831
self.0.available(cx)
3932
}
4033

41-
/// Get total number of acquired counts
34+
/// Get total number of acquired guards.
4235
pub fn total(&self) -> usize {
4336
self.0.count.get()
4437
}
4538
}
4639

47-
pub struct CounterGuard(Rc<CounterInner>);
48-
49-
impl CounterGuard {
50-
fn new(inner: Rc<CounterInner>) -> Self {
51-
inner.inc();
52-
CounterGuard(inner)
53-
}
54-
}
55-
56-
impl Unpin for CounterGuard {}
57-
58-
impl Drop for CounterGuard {
59-
fn drop(&mut self) {
60-
self.0.dec();
61-
}
40+
struct CounterInner {
41+
count: Cell<usize>,
42+
capacity: usize,
43+
task: LocalWaker,
6244
}
6345

6446
impl CounterInner {
@@ -83,3 +65,32 @@ impl CounterInner {
8365
}
8466
}
8567
}
68+
69+
impl fmt::Debug for CounterInner {
70+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71+
f.debug_struct("Counter")
72+
.field("count", &self.count.get())
73+
.field("capacity", &self.capacity)
74+
.field("task", &self.task)
75+
.finish()
76+
}
77+
}
78+
79+
/// An RAII structure that keeps the underlying counter incremented until this guard is dropped.
80+
#[derive(Debug)]
81+
pub struct CounterGuard(Rc<CounterInner>);
82+
83+
impl CounterGuard {
84+
fn new(inner: Rc<CounterInner>) -> Self {
85+
inner.inc();
86+
CounterGuard(inner)
87+
}
88+
}
89+
90+
impl Unpin for CounterGuard {}
91+
92+
impl Drop for CounterGuard {
93+
fn drop(&mut self) {
94+
self.0.dec();
95+
}
96+
}

actix-utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Various network related services and utilities for the Actix ecosystem.
1+
//! Various utilities for the Actix ecosystem.
22
33
#![deny(rust_2018_idioms, nonstandard_style)]
4-
#![allow(clippy::type_complexity)]
4+
#![warn(missing_docs)]
55
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
66
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
77

0 commit comments

Comments
 (0)