Skip to content

Commit 1db6310

Browse files
committed
instituted sane-people naming for counter types
1 parent abd9a82 commit 1db6310

12 files changed

+28
-46
lines changed

rc/examples/01-count.rs renamed to rc/examples/01-simple.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use rc::count::Count;
1+
use rc::simple::Counter;
22

33
/// Increment the given count. Note that this function takes
44
/// `count` by mutable reference.
5-
fn update_count(count: &mut Count) {
5+
fn update_count(count: &mut Counter) {
66
count.incr();
77
}
88

99
fn main() {
10-
let mut count = Count::default();
10+
let mut count = Counter::default();
1111
println!("{}", count.value());
1212
update_count(&mut count);
1313
println!("{}", count.value());

rc/examples/02-badcount.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use rc::count::Count;
1+
use rc::simple::Counter;
22

33
/// A "message" struct. More later.
44
struct Message<'a> {
55
note: &'static str,
6-
counter: &'a mut Count,
6+
counter: &'a mut Counter,
77
}
88

99
/// Increment the given count. Note that this function takes
@@ -20,7 +20,7 @@ fn main() {
2020
todo!();
2121
// This code will fail to compile because of two mutable
2222
// references to `count`.
23-
let mut count = Count::default();
23+
let mut count = Counter::default();
2424
let mut left = Message { note: "left", counter: &mut count };
2525
let mut right = Message { note: "right", counter: &mut count };
2626
left.update_count();

rc/examples/04-messages.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use rc::message::Message;
21
use rc::misc::make_messages;
3-
use rc::counter::Counter;
42

53
fn main() {
64
let (m1, m2) = make_messages("m1", "m2");

rc/examples/03-counter.rs renamed to rc/examples/06-cell.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// https://doc.rust-lang.org/std/cell/
2-
use rc::counter::Counter;
1+
use rc::cell::Counter;
32

43
/// Increment the given counter. Note that this function
54
/// takes `counter` by immutable reference.
@@ -12,5 +11,4 @@ fn main() {
1211
println!("{}", counter.value());
1312
update_counter(&counter);
1413
println!("{}", counter.value());
15-
println!("{}", counter.incr_value());
1614
}

rc/examples/06-ctr.rs

-14
This file was deleted.

rc/src/ctr.rs renamed to rc/src/cell.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
use std::cell::Cell;
22

3-
use crate::count::Count;
3+
use crate::simple;
44

55
/// An interior-mutable counter over the restricted `Count`.
66
#[derive(Default)]
7-
pub struct Ctr(Cell<Count>);
7+
pub struct Counter(Cell<simple::Counter>);
88

9-
impl Ctr {
9+
impl Counter {
1010
/// Increase the count of the contained counter by one.
1111
/// Note that this method takes `self` by immutable
1212
/// reference, then changes it anyway.
1313
pub fn incr(&self) {
14-
let mut count = self.0.replace(Count::default());
14+
let mut count = self.0.replace(simple::Counter::default());
1515
count.incr();
1616
let _ = self.0.replace(count);
1717
}
1818

1919
/// Return the value of the contained counter.
2020
pub fn value(&self) -> u64 {
21-
let count = self.0.replace(Count::default());
21+
let count = self.0.replace(simple::Counter::default());
2222
let value = count.value();
2323
let _ = self.0.replace(count);
2424
value

rc/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Counting-related ADTs.
22
3-
pub mod count;
4-
pub mod counter;
3+
pub mod simple;
4+
pub mod cell;
5+
pub mod refcell;
56
pub mod message;
6-
pub mod ctr;
77
pub mod misc;

rc/src/message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! assert_eq!(htmp.text(), "hello");
1212
//! assert_eq!(hello.accesses(), 2);
1313
14-
use crate::counter::Counter;
14+
use crate::refcell::Counter;
1515

1616
/// Message to print plus usage counter.
1717
#[derive(Debug, Clone)]

rc/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::counter::Counter;
1+
use crate::refcell::Counter;
22
use crate::message::Message;
33

44
/// Make a couple of messages with given message strings.

rc/src/counter.rs renamed to rc/src/refcell.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! # Examples
44
//!
5-
//! # use rc::counter::Counter;
5+
//! # use rc::refcell::Counter;
66
//! let c0 = Counter::default();
77
//! c0.incr();
88
//! assert_eq!(c0.value(), 1);
@@ -12,14 +12,14 @@
1212
//! assert_eq!(c0.value(), 3);
1313
//! assert_eq!(c1.value(), 3);
1414
15-
use crate::count::Count;
15+
use crate::simple;
1616

1717
use std::cell::{RefCell, RefMut};
1818
use std::rc::Rc;
1919

20-
/// An interior-mutable shared counter over the restricted `Count`.
20+
/// An interior-mutable shared counter over the restricted `simple::Counter`.
2121
#[derive(Debug, Default, Clone)]
22-
pub struct Counter(Rc<RefCell<Count>>);
22+
pub struct Counter(Rc<RefCell<simple::Counter>>);
2323

2424
impl Counter {
2525
// Note that this method takes `self` by immutable
@@ -42,7 +42,7 @@ impl Counter {
4242
self.value()
4343
}
4444

45-
pub fn count_mut(&self) -> RefMut<Count> {
45+
pub fn count_mut(&self) -> RefMut<simple::Counter> {
4646
self.0.borrow_mut()
4747
}
4848
}

rc/src/count.rs renamed to rc/src/simple.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
//!
33
//! # Examples
44
//!
5-
//! # use rc::count::Count;
6-
//! let mut count = Count::default();
5+
//! # use rc::simple::Counter;
6+
//! let mut count = Counter::default();
77
//! count.incr();
88
//! assert_eq!(count.value(), 1);
99
10-
/// A non-negative count.
10+
/// A non-negative counter.
1111
#[derive(Debug, Default)]
12-
pub struct Count(u64);
12+
pub struct Counter(u64);
1313

14-
impl Count {
14+
impl Counter {
1515
/// Increase the count by one.
1616
pub fn incr(&mut self) {
1717
self.0 += 1;

rc/tests/double-ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rc::counter::Counter;
1+
use rc::refcell::Counter;
22

33
#[test]
44
#[should_panic]

0 commit comments

Comments
 (0)