Skip to content

Commit 73e6754

Browse files
committed
remove mut reference client
1 parent 40b727e commit 73e6754

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

examples/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate statsd;
55
use statsd::client::Client;
66

77
fn main() {
8-
let mut client = Client::new("127.0.0.1:8125", "myapp").unwrap();
8+
let client = Client::new("127.0.0.1:8125", "myapp").unwrap();
99
client.incr("some.counter");
1010
println!("Sent a counter!");
1111

src/client.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Client {
9696
///
9797
/// This modifies a counter with an effective sampling
9898
/// rate of 1.0.
99-
pub fn incr(&mut self, metric: &str) {
99+
pub fn incr(&self, metric: &str) {
100100
self.count(metric, 1.0);
101101
}
102102

@@ -109,7 +109,7 @@ impl Client {
109109
///
110110
/// This modifies a counter with an effective sampling
111111
/// rate of 1.0.
112-
pub fn decr(&mut self, metric: &str) {
112+
pub fn decr(&self, metric: &str) {
113113
self.count(metric, -1.0);
114114
}
115115

@@ -122,7 +122,7 @@ impl Client {
122122
/// // Increment by 12
123123
/// client.count("metric.completed", 12.0);
124124
/// ```
125-
pub fn count(&mut self, metric: &str, value: f64) {
125+
pub fn count(&self, metric: &str, value: f64) {
126126
let data = self.prepare(format!("{}:{}|c", metric, value));
127127
self.send(data);
128128
}
@@ -137,7 +137,7 @@ impl Client {
137137
/// // Increment by 4 50% of the time.
138138
/// client.sampled_count("metric.completed", 4, 0.5);
139139
/// ```
140-
pub fn sampled_count(&mut self, metric: &str, value: f64, rate: f64) {
140+
pub fn sampled_count(&self, metric: &str, value: f64, rate: f64) {
141141
if rand::random::<f64>() < rate {
142142
return;
143143
}
@@ -151,7 +151,7 @@ impl Client {
151151
/// // set a gauge to 9001
152152
/// client.gauge("power_level.observed", 9001.0);
153153
/// ```
154-
pub fn gauge(&mut self, metric: &str, value: f64) {
154+
pub fn gauge(&self, metric: &str, value: f64) {
155155
let data = self.prepare(format!("{}:{}|g", metric, value));
156156
self.send(data);
157157
}
@@ -164,7 +164,7 @@ impl Client {
164164
/// // pass a duration value
165165
/// client.timer("response.duration", 10.123);
166166
/// ```
167-
pub fn timer(&mut self, metric: &str, value: f64) {
167+
pub fn timer(&self, metric: &str, value: f64) {
168168
let data = self.prepare(format!("{}:{}|ms", metric, value));
169169
self.send(data);
170170
}
@@ -180,7 +180,7 @@ impl Client {
180180
/// // Your code here.
181181
/// });
182182
/// ```
183-
pub fn time<F, R>(&mut self, metric: &str, callable: F) -> R
183+
pub fn time<F, R>(&self, metric: &str, callable: F) -> R
184184
where F: Fn() -> R
185185
{
186186
let start = time::Instant::now();
@@ -197,7 +197,7 @@ impl Client {
197197
}
198198

199199
/// Send data along the UDP socket.
200-
fn send(&mut self, data: String) {
200+
fn send(&self, data: String) {
201201
let _ = self.socket.send_to(data.as_bytes(), self.server_address);
202202
}
203203

@@ -364,7 +364,7 @@ impl Pipeline {
364364
}
365365

366366
/// Send data along the UDP socket.
367-
pub fn send(&mut self, client: &mut Client) {
367+
pub fn send(&mut self, client: &Client) {
368368
let mut _data = String::new();
369369
if let Some(data) = self.stats.pop_front() {
370370
_data = _data + client.prepare(&data).as_ref();
@@ -435,7 +435,7 @@ mod test {
435435
fn test_sending_gauge() {
436436
let host = next_test_ip4();
437437
let server = make_server(&host);
438-
let mut client = Client::new(&host, "myapp").unwrap();
438+
let client = Client::new(&host, "myapp").unwrap();
439439

440440
client.gauge("metric", 9.1);
441441

@@ -447,7 +447,7 @@ mod test {
447447
fn test_sending_incr() {
448448
let host = next_test_ip4();
449449
let server = make_server(&host);
450-
let mut client = Client::new(&host, "myapp").unwrap();
450+
let client = Client::new(&host, "myapp").unwrap();
451451

452452
client.incr("metric");
453453

@@ -459,7 +459,7 @@ mod test {
459459
fn test_sending_decr() {
460460
let host = next_test_ip4();
461461
let server = make_server(&host);
462-
let mut client = Client::new(&host, "myapp").unwrap();
462+
let client = Client::new(&host, "myapp").unwrap();
463463

464464
client.decr("metric");
465465

@@ -471,7 +471,7 @@ mod test {
471471
fn test_sending_count() {
472472
let host = next_test_ip4();
473473
let server = make_server(&host);
474-
let mut client = Client::new(&host, "myapp").unwrap();
474+
let client = Client::new(&host, "myapp").unwrap();
475475

476476
client.count("metric", 12.2);
477477

@@ -483,7 +483,7 @@ mod test {
483483
fn test_sending_timer() {
484484
let host = next_test_ip4();
485485
let server = make_server(&host);
486-
let mut client = Client::new(&host, "myapp").unwrap();
486+
let client = Client::new(&host, "myapp").unwrap();
487487

488488
client.timer("metric", 21.39);
489489

@@ -495,7 +495,7 @@ mod test {
495495
fn test_sending_timed_block() {
496496
let host = next_test_ip4();
497497
let server = make_server(&host);
498-
let mut client = Client::new(&host, "myapp").unwrap();
498+
let client = Client::new(&host, "myapp").unwrap();
499499

500500
let output = client.time("metric", || {
501501
"a string"
@@ -511,10 +511,10 @@ mod test {
511511
fn test_pipeline_sending_gauge() {
512512
let host = next_test_ip4();
513513
let server = make_server(&host);
514-
let mut client = Client::new(&host, "myapp").unwrap();
514+
let client = Client::new(&host, "myapp").unwrap();
515515
let mut pipeline = client.pipeline();
516516
pipeline.gauge("metric", 9.1);
517-
pipeline.send(&mut client);
517+
pipeline.send(&client);
518518

519519
let response = server_recv(server);
520520
assert_eq!("myapp.metric:9.1|g", response);
@@ -524,11 +524,11 @@ mod test {
524524
fn test_pipeline_sending_multiple_data() {
525525
let host = next_test_ip4();
526526
let server = make_server(&host);
527-
let mut client = Client::new(&host, "myapp").unwrap();
527+
let client = Client::new(&host, "myapp").unwrap();
528528
let mut pipeline = client.pipeline();
529529
pipeline.gauge("metric", 9.1);
530530
pipeline.count("metric", 12.2);
531-
pipeline.send(&mut client);
531+
pipeline.send(&client);
532532

533533
let response = server_recv(server);
534534
assert_eq!("myapp.metric:9.1|g\nmyapp.metric:12.2|c", response);
@@ -538,12 +538,12 @@ mod test {
538538
fn test_pipeline_set_max_udp_size() {
539539
let host = next_test_ip4();
540540
let server = make_server(&host);
541-
let mut client = Client::new(&host, "myapp").unwrap();
541+
let client = Client::new(&host, "myapp").unwrap();
542542
let mut pipeline = client.pipeline();
543543
pipeline.set_max_udp_size(20);
544544
pipeline.gauge("metric", 9.1);
545545
pipeline.count("metric", 12.2);
546-
pipeline.send(&mut client);
546+
pipeline.send(&client);
547547

548548
let response = server_recv(server);
549549
assert_eq!("myapp.metric:9.1|g", response);
@@ -553,12 +553,12 @@ mod test {
553553
fn test_pipeline_send_metric_after_pipeline() {
554554
let host = next_test_ip4();
555555
let server = make_server(&host);
556-
let mut client = Client::new(&host, "myapp").unwrap();
556+
let client = Client::new(&host, "myapp").unwrap();
557557
let mut pipeline = client.pipeline();
558558

559559
pipeline.gauge("load", 9.0);
560560
pipeline.count("customers", 7.0);
561-
pipeline.send(&mut client);
561+
pipeline.send(&client);
562562

563563
// Should still be able to send metrics
564564
// with the client.

0 commit comments

Comments
 (0)