Skip to content

Commit c7e97ba

Browse files
committed
Create a mithril-resource-pool module
1 parent b379808 commit c7e97ba

File tree

13 files changed

+86
-22
lines changed

13 files changed

+86
-22
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"internal/mithril-doc-derive",
1414
"internal/mithril-metric",
1515
"internal/mithril-persistence",
16+
"internal/mithril-resource-pool",
1617
"mithril-aggregator",
1718
"mithril-client",
1819
"mithril-client-cli",

internal/mithril-persistence/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async-trait = "0.1.86"
1717
chrono = { version = "0.4.39", features = ["serde"] }
1818
hex = "0.4.3"
1919
mithril-common = { path = "../../mithril-common", features = ["fs"] }
20+
mithril-resource-pool = { path = "../mithril-resource-pool" }
2021
semver = "1.0.25"
2122
serde = { version = "1.0.217", features = ["derive"] }
2223
serde_json = "1.0.138"

internal/mithril-persistence/src/sqlite/connection_pool.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::{ops::Deref, time::Duration};
22

3-
use mithril_common::{
4-
resource_pool::{Reset, ResourcePool, ResourcePoolItem},
5-
StdResult,
6-
};
3+
use mithril_common::{Reset, StdResult};
4+
use mithril_resource_pool::{ResourcePool, ResourcePoolItem};
75

86
use crate::sqlite::SqliteConnection;
97

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "mithril-resource-pool"
3+
version = "0.0.1"
4+
description = "Provide a resource pool for Mithril."
5+
authors = { workspace = true }
6+
edition = { workspace = true }
7+
homepage = { workspace = true }
8+
license = { workspace = true }
9+
repository = { workspace = true }
10+
11+
[lib]
12+
crate-type = ["lib", "cdylib", "staticlib"]
13+
14+
[dependencies]
15+
anyhow = "1.0.95"
16+
mithril-common = { path = "../../mithril-common", features = ["fs"] }
17+
thiserror = "2.0.11"
18+
tokio = { version = "1.43.0", features = ["sync"] }
19+
20+
[dev-dependencies]
21+
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
22+
mockall = "0.13.1"
23+
tokio = { version = "1.43.0", features = ["macros", "time"] }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: all build test check doc
2+
3+
CARGO = cargo
4+
5+
all: test build
6+
7+
build:
8+
${CARGO} build --release
9+
10+
test:
11+
${CARGO} test
12+
13+
check:
14+
${CARGO} check --release --all-features --all-targets
15+
${CARGO} clippy --release --all-features --all-targets
16+
${CARGO} fmt --check
17+
18+
doc:
19+
${CARGO} doc --no-deps --open --features full
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Mithril-resource-pool
2+
3+
This crate provide a resource pool for Mithril.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![warn(missing_docs)]
2+
3+
//! Provide a resource pool for Mithril.
4+
5+
mod resource_pool;
6+
7+
pub use resource_pool::*;

mithril-common/src/resource_pool.rs renamed to internal/mithril-resource-pool/src/resource_pool.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
};
1010
use thiserror::Error;
1111

12-
use crate::StdResult;
12+
use mithril_common::{Reset, StdResult};
1313

1414
/// [ResourcePool] related errors.
1515
#[derive(Error, Debug)]
@@ -207,20 +207,6 @@ impl<T: Reset + Send + Sync> Drop for ResourcePoolItem<'_, T> {
207207
}
208208
}
209209

210-
/// Reset trait which is implemented by pooled resource items.
211-
/// As pool resource items are mutable, this will guarantee that the pool stays consistent
212-
/// and that acquired resource items do not depend from previous computations.
213-
pub trait Reset {
214-
/// Reset the resource
215-
fn reset(&mut self) -> StdResult<()> {
216-
Ok(())
217-
}
218-
}
219-
220-
cfg_test_tools! {
221-
impl Reset for String {}
222-
}
223-
224210
#[cfg(test)]
225211
mod tests {
226212
use std::time::Duration;

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mithril-common = { path = "../mithril-common", features = ["full"] }
3030
mithril-doc = { path = "../internal/mithril-doc" }
3131
mithril-metric = { path = "../internal/mithril-metric" }
3232
mithril-persistence = { path = "../internal/mithril-persistence" }
33+
mithril-resource-pool = { path = "../internal/mithril-resource-pool" }
3334
paste = "1.0.15"
3435
prometheus = "0.13.4"
3536
rayon = "1.10.0"

0 commit comments

Comments
 (0)