Skip to content

Commit 25eb33b

Browse files
Atul9dpc
authored andcommitted
Format code using 'cargo fmt'
1 parent 67424c9 commit 25eb33b

File tree

1 file changed

+60
-48
lines changed

1 file changed

+60
-48
lines changed

lib.rs

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@
5050

5151
#[macro_use]
5252
extern crate slog;
53-
extern crate thread_local;
54-
extern crate take_mut;
5553
extern crate crossbeam_channel;
54+
extern crate take_mut;
55+
extern crate thread_local;
5656

5757
use crossbeam_channel::Sender;
5858

59-
use slog::{Record, RecordStatic, Level, SingleKV, KV, BorrowedKV};
60-
use slog::{Serializer, OwnedKVList, Key};
59+
use slog::{BorrowedKV, Level, Record, RecordStatic, SingleKV, KV};
60+
use slog::{Key, OwnedKVList, Serializer};
6161

6262
use slog::Drain;
63-
use std::{io, thread};
6463
use std::error::Error;
6564
use std::fmt;
6665
use std::sync;
66+
use std::{io, thread};
6767

68-
use std::sync::Mutex;
6968
use std::sync::atomic::AtomicUsize;
7069
use std::sync::atomic::Ordering;
70+
use std::sync::Mutex;
7171
use take_mut::take;
7272
// }}}
7373

@@ -168,7 +168,11 @@ impl Serializer for ToSendSerializer {
168168
}
169169

170170
#[cfg(feature = "nested-values")]
171-
fn emit_serde(&mut self, key: Key, value: &slog::SerdeValue) -> slog::Result {
171+
fn emit_serde(
172+
&mut self,
173+
key: Key,
174+
value: &slog::SerdeValue,
175+
) -> slog::Result {
172176
let val = value.to_sendable();
173177
take(&mut self.kv, |kv| Box::new((kv, SingleKV(key, val))));
174178
Ok(())
@@ -195,17 +199,19 @@ impl<T> From<crossbeam_channel::TrySendError<T>> for AsyncError {
195199

196200
impl<T> From<crossbeam_channel::SendError<T>> for AsyncError {
197201
fn from(_: crossbeam_channel::SendError<T>) -> AsyncError {
198-
AsyncError::Fatal(Box::new(
199-
io::Error::new(io::ErrorKind::BrokenPipe, "The logger thread terminated"),
200-
))
202+
AsyncError::Fatal(Box::new(io::Error::new(
203+
io::ErrorKind::BrokenPipe,
204+
"The logger thread terminated",
205+
)))
201206
}
202207
}
203208

204209
impl<T> From<std::sync::PoisonError<T>> for AsyncError {
205210
fn from(err: std::sync::PoisonError<T>) -> AsyncError {
206-
AsyncError::Fatal(Box::new(
207-
io::Error::new(io::ErrorKind::BrokenPipe, err.description()),
208-
))
211+
AsyncError::Fatal(Box::new(io::Error::new(
212+
io::ErrorKind::BrokenPipe,
213+
err.description(),
214+
)))
209215
}
210216
}
211217

@@ -268,23 +274,23 @@ where
268274
self
269275
}
270276

271-
fn spawn_thread(
272-
self,
273-
) -> (thread::JoinHandle<()>, Sender<AsyncMsg>) {
277+
fn spawn_thread(self) -> (thread::JoinHandle<()>, Sender<AsyncMsg>) {
274278
let (tx, rx) = crossbeam_channel::bounded(self.chan_size);
275279
let mut builder = thread::Builder::new();
276280
if let Some(thread_name) = self.thread_name {
277281
builder = builder.name(thread_name);
278282
}
279283
let drain = self.drain;
280-
let join = builder.spawn(move || loop {
281-
match rx.recv().unwrap() {
282-
AsyncMsg::Record(r) => {
283-
r.log_to(&drain).unwrap();
284+
let join = builder
285+
.spawn(move || loop {
286+
match rx.recv().unwrap() {
287+
AsyncMsg::Record(r) => {
288+
r.log_to(&drain).unwrap();
289+
}
290+
AsyncMsg::Finish => return,
284291
}
285-
AsyncMsg::Finish => return,
286-
}
287-
}).unwrap();
292+
})
293+
.unwrap();
288294

289295
(join, tx)
290296
}
@@ -410,10 +416,11 @@ impl AsyncCore {
410416
&self,
411417
) -> Result<
412418
&crossbeam_channel::Sender<AsyncMsg>,
413-
std::sync::PoisonError<sync::MutexGuard<crossbeam_channel::Sender<AsyncMsg>>>,
419+
std::sync::PoisonError<
420+
sync::MutexGuard<crossbeam_channel::Sender<AsyncMsg>>,
421+
>,
414422
> {
415-
self.tl_sender
416-
.get_or_try(|| Ok(self.ref_sender.clone()))
423+
self.tl_sender.get_or_try(|| Ok(self.ref_sender.clone()))
417424
}
418425

419426
/// Send `AsyncRecord` to a worker thread.
@@ -439,7 +446,6 @@ impl Drain for AsyncCore {
439446
record: &Record,
440447
logger_values: &OwnedKVList,
441448
) -> AsyncResult<()> {
442-
443449
let mut ser = ToSendSerializer::new();
444450
record
445451
.kv()
@@ -487,15 +493,14 @@ impl AsyncRecord {
487493
tag: &self.tag,
488494
};
489495

490-
drain
491-
.log(
492-
&Record::new(
493-
&rs,
494-
&format_args!("{}", self.msg),
495-
BorrowedKV(&self.kv),
496-
),
497-
&self.logger_values,
498-
)
496+
drain.log(
497+
&Record::new(
498+
&rs,
499+
&format_args!("{}", self.msg),
500+
BorrowedKV(&self.kv),
501+
),
502+
&self.logger_values,
503+
)
499504
}
500505

501506
/// Deconstruct this `AsyncRecord` into a record and `OwnedKVList`.
@@ -506,11 +511,14 @@ impl AsyncRecord {
506511
tag: &self.tag,
507512
};
508513

509-
f(&Record::new(
510-
&rs,
511-
&format_args!("{}", self.msg),
512-
BorrowedKV(&self.kv),
513-
), &self.logger_values)
514+
f(
515+
&Record::new(
516+
&rs,
517+
&format_args!("{}", self.msg),
518+
BorrowedKV(&self.kv),
519+
),
520+
&self.logger_values,
521+
)
514522
}
515523
}
516524

@@ -597,17 +605,22 @@ where
597605
pub fn chan_size(self, s: usize) -> Self {
598606
AsyncBuilder {
599607
core: self.core.chan_size(s),
600-
.. self
608+
..self
601609
}
602610
}
603611

604612
/// Sets what will happen if the channel is full.
605-
pub fn overflow_strategy(self, overflow_strategy: OverflowStrategy) -> Self {
613+
pub fn overflow_strategy(
614+
self,
615+
overflow_strategy: OverflowStrategy,
616+
) -> Self {
606617
let (block, inc) = match overflow_strategy {
607618
OverflowStrategy::Block => (true, false),
608619
OverflowStrategy::Drop => (false, false),
609620
OverflowStrategy::DropAndReport => (false, true),
610-
OverflowStrategy::DoNotMatchAgainstThisAndReadTheDocs => panic!("Invalid variant"),
621+
OverflowStrategy::DoNotMatchAgainstThisAndReadTheDocs => {
622+
panic!("Invalid variant")
623+
}
611624
};
612625
AsyncBuilder {
613626
core: self.core.blocking(block),
@@ -625,7 +638,7 @@ where
625638
pub fn thread_name(self, name: String) -> Self {
626639
AsyncBuilder {
627640
core: self.core.thread_name(name),
628-
.. self
641+
..self
629642
}
630643
}
631644

@@ -750,15 +763,14 @@ impl Drain for Async {
750763
record: &Record,
751764
logger_values: &OwnedKVList,
752765
) -> AsyncResult<()> {
753-
754766
self.push_dropped(logger_values)?;
755767

756768
match self.core.log(record, logger_values) {
757769
Ok(()) => {}
758770
Err(AsyncError::Full) if self.inc_dropped => {
759771
self.dropped.fetch_add(1, Ordering::Relaxed);
760-
},
761-
Err(AsyncError::Full) => {},
772+
}
773+
Err(AsyncError::Full) => {}
762774
Err(e) => return Err(e),
763775
}
764776

0 commit comments

Comments
 (0)