File: singlethread.rs

package info (click to toggle)
rust-slog 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: makefile: 60
file content (29 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//#![feature(nothreads)]
#[macro_use]
extern crate slog;
use slog::{Fuse, Logger};
use std::cell::RefCell;
use std::rc::Rc;

mod common;

#[derive(Clone)]
struct NoThreadSafeObject {
    val: Rc<RefCell<usize>>,
}

fn main() {
    let log = Logger::root(Fuse(common::PrintlnDrain), o!("version" => "2"));
    let obj = NoThreadSafeObject {
        val: Rc::new(RefCell::new(4)),
    };

    // Move obj2 into a closure. Since it's !Send, this only works
    // with nothreads feature.
    let obj2 = obj.clone();
    let sublog = log.new(o!("obj.val" => slog::FnValue(move |_| {
        format!("{}", obj2.val.borrow())
    })));

    info!(sublog, "test");
}