File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ documentation = "https://docs.rs/slog"
10
10
homepage = " https://github.com/slog-rs/slog"
11
11
repository = " https://github.com/slog-rs/slog"
12
12
readme = " README.md"
13
+ autoexamples = true
13
14
14
15
build = " build.rs"
15
16
@@ -49,6 +50,10 @@ release_max_level_trace = []
49
50
[dependencies ]
50
51
erased-serde = { version = " 0.3" , optional = true }
51
52
53
+ [[example ]]
54
+ name = " singlethread"
55
+ required-features = [" nothreads" ]
56
+
52
57
[package .metadata .docs .rs ]
53
58
features = [" std" , " nested-values" , " dynamic-keys" ]
54
59
Original file line number Diff line number Diff line change @@ -48,8 +48,10 @@ longtest:
48
48
@i=0; while i=$$ (( i + 1 )) && echo " Iteration $$ i" && make test ; do : ; done
49
49
50
50
.PHONY : $(EXAMPLES )
51
- $( EXAMPLES ) :
51
+ named struct-log-self :
52
52
cargo build --example $@ $(CARGO_FLAGS )
53
+ singlethread :
54
+ cargo build --features nothreads --example $@ $(CARGO_FLAGS )
53
55
54
56
.PHONY : doc
55
57
doc : FORCE
Original file line number Diff line number Diff line change
1
+ //#![feature(nothreads)]
2
+ #[ macro_use]
3
+ extern crate slog;
4
+ use slog:: { Fuse , Logger } ;
5
+ use std:: cell:: RefCell ;
6
+ use std:: rc:: Rc ;
7
+
8
+ mod common;
9
+
10
+ #[ derive( Clone ) ]
11
+ struct NoThreadSafeObject {
12
+ val : Rc < RefCell < usize > > ,
13
+ }
14
+
15
+ fn main ( ) {
16
+ let log = Logger :: root ( Fuse ( common:: PrintlnDrain ) , o ! ( "version" => "2" ) ) ;
17
+ let obj = NoThreadSafeObject {
18
+ val : Rc :: new ( RefCell :: new ( 4 ) ) ,
19
+ } ;
20
+
21
+ // Move obj2 into a closure. Since it's !Send, this only works
22
+ // with nothreads feature.
23
+ let obj2 = obj. clone ( ) ;
24
+ let sublog = log. new ( o ! ( "obj.val" => slog:: FnValue ( move |_| {
25
+ format!( "{}" , obj2. val. borrow( ) )
26
+ } ) ) ) ;
27
+
28
+ info ! ( sublog, "test" ) ;
29
+ }
You can’t perform that action at this time.
0 commit comments