3 个版本 (重大更新)

0.2.0 2021 年 10 月 25 日
0.1.0 2019 年 9 月 1 日
0.0.1 2019 年 8 月 30 日

#13 in #connection-manager

Apache-2.0 OR MIT

7KB
75 行代码(不含注释)

r2d2-jfs

r2d2-jfs

JSON 文件存储 (jfs)r2d2 连接池的支持。

示例

use std::thread;
use serde::{Serialize, Deserialize};
use r2d2_jfs::JfsConnectionManager;

#[derive(Serialize, Deserialize)]
struct Data { x: i32 }

fn main() {
    let manager = JfsConnectionManager::file("file.json").unwrap();
    let pool = r2d2::Pool::builder().max_size(5).build(manager).unwrap();
    let mut threads = vec![];
    for i in 0..10 {
        let pool = pool.clone();
        threads.push(thread::spawn(move || {
            let d = Data { x: i };
            let conn = pool.get().unwrap();
            conn.save(&d).unwrap();
        }));
    }
    for c in threads {
        c.join().unwrap();
    }
}

许可证: Apache-2.0 OR MIT


lib.rs:

r2d2-jfs

JSON 文件存储 (jfs)r2d2 连接池的支持。

示例

use std::thread;
use serde::{Serialize, Deserialize};
use r2d2_jfs::JfsConnectionManager;

#[derive(Serialize, Deserialize)]
struct Data { x: i32 }

let manager = JfsConnectionManager::file("file.json").unwrap();
let pool = r2d2::Pool::builder().max_size(5).build(manager).unwrap();
let mut threads = vec![];
for i in 0..10 {
   let pool = pool.clone();
   threads.push(thread::spawn(move || {
       let d = Data { x: i };
       let conn = pool.get().unwrap();
       conn.save(&d).unwrap();
   }));
}
for c in threads {
   c.join().unwrap();
}

依赖项

~1.2–7.5MB
~40K SLoC