Skip to content

Commit

Permalink
safe code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Apr 11, 2020
1 parent 79808f5 commit 9b407a1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fast_log"
version = "1.0.3"
version = "1.0.4"
description = "Rust async log 高性能异步日志"
readme = "Readme.md"
authors = ["ce <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# log
the fast log
the fast log . This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

* how to use?
```toml
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![forbid(unsafe_code)]

#[macro_use]
extern crate lazy_static;
Expand Down
8 changes: 3 additions & 5 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,25 @@ use crate::time_util;

pub struct SimpleLogger {
pub sender: std::sync::mpsc::SyncSender<String>,
pub recv: std::sync::mpsc::Receiver<String>,
pub recv: Mutex<std::sync::mpsc::Receiver<String>>,
}

unsafe impl Send for SimpleLogger {}

unsafe impl Sync for SimpleLogger {}

impl SimpleLogger {
pub fn new() -> Self {
let (s, r) = std::sync::mpsc::sync_channel(1000);
return Self {
sender: s,
recv: r,
recv: Mutex::new(r)
};
}
pub fn send(&self, arg: String) {
self.sender.send(arg);
}

pub fn recv(&self) -> Result<String, RecvError> {
self.recv.recv()
self.recv.lock().unwrap().recv()
}
}

Expand Down

0 comments on commit 9b407a1

Please sign in to comment.