Debian Codegraph @

src/common.rs

raw symbols SCIP
1 use craterust-analyzer cargo threadfin 0.1.2 crate/::{Builderrust-analyzer cargo threadfin 0.1.2 pool/Builder#, CommonAlreadyInitializedErrorrust-analyzer cargo threadfin 0.1.2 error/CommonAlreadyInitializedError#, ThreadPoolrust-analyzer cargo threadfin 0.1.2 pool/ThreadPool#};
2 use once_cellrust-analyzer cargo once_cell 1.21.4 crate/::syncrust-analyzer cargo once_cell 1.21.4 sync/::OnceCellrust-analyzer cargo once_cell 1.21.4 sync/OnceCell#;
3
4 static COMMONrust-analyzer cargo threadfin 0.1.2 common/COMMON.: OnceCellrust-analyzer cargo once_cell 1.21.4 sync/OnceCell#<ThreadPoolrust-analyzer cargo threadfin 0.1.2 pool/ThreadPool#> = OnceCellrust-analyzer cargo once_cell 1.21.4 sync/OnceCell#::newrust-analyzer cargo once_cell 1.21.4 sync/impl#[`OnceCell<T>`]new().();
5
6 /// Get a shared reference to a common thread pool for the entire process.
7 ///
8 /// # Examples
9 ///
10 /// ```
11 /// let result = threadfin::common().execute(|| 2 + 2).join();
12 ///
13 /// assert_eq!(result, 4);
14 /// ```
15 pub fn commonrust-analyzer cargo threadfin 0.1.2 common/common().() -> &'static ThreadPoolrust-analyzer cargo threadfin 0.1.2 pool/ThreadPool# {
16 COMMONrust-analyzer cargo threadfin 0.1.2 common/COMMON..get_or_initrust-analyzer cargo once_cell 1.21.4 sync/impl#[`OnceCell<T>`]get_or_init().(|| common_builderrust-analyzer cargo threadfin 0.1.2 common/common_builder().().buildrust-analyzer cargo threadfin 0.1.2 pool/impl#[Builder]build().())
17 }
18
19 /// Configure the common thread pool.
20 ///
21 /// This should be done near the start of your program before any other code
22 /// uses the common pool, as this function will return an error if the common
23 /// pool has already been initialized.
24 ///
25 /// Only programs should use this function! Libraries should not use this
26 /// function and instead allow the running program to configure the common pool.
27 /// If you need a customized pool in a library then you should use a separate
28 /// pool instance.
29 ///
30 /// # Examples
31 ///
32 /// ```
33 /// threadfin::configure_common(|builder| builder
34 /// .size(3)
35 /// .queue_limit(1024))
36 /// .unwrap();
37 ///
38 /// assert_eq!(threadfin::common().threads(), 3);
39 /// ```
40 pub fn configure_commonrust-analyzer cargo threadfin 0.1.2 common/configure_common().<F>(f: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), CommonAlreadyInitializedErrorrust-analyzer cargo threadfin 0.1.2 error/CommonAlreadyInitializedError#>
41 where
42 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(Builderrust-analyzer cargo threadfin 0.1.2 pool/Builder#) -> Builderrust-analyzer cargo threadfin 0.1.2 pool/Builder#,
43 {
44 let mut was_initialized = true;
45
46 COMMONrust-analyzer cargo threadfin 0.1.2 common/COMMON..get_or_initrust-analyzer cargo once_cell 1.21.4 sync/impl#[`OnceCell<T>`]get_or_init().(|| {
47 was_initialized = false;
48 f(common_builderrust-analyzer cargo threadfin 0.1.2 common/common_builder().()).buildrust-analyzer cargo threadfin 0.1.2 pool/impl#[Builder]build().()
49 });
50
51 if was_initialized {
52 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(CommonAlreadyInitializedErrorrust-analyzer cargo threadfin 0.1.2 error/CommonAlreadyInitializedError#::newrust-analyzer cargo threadfin 0.1.2 error/impl#[CommonAlreadyInitializedError]new().())
53 } else {
54 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
55 }
56 }
57
58 fn common_builderrust-analyzer cargo threadfin 0.1.2 common/common_builder().() -> Builderrust-analyzer cargo threadfin 0.1.2 pool/Builder# {
59 Builderrust-analyzer cargo threadfin 0.1.2 pool/Builder#::defaultrust-analyzer cargo threadfin 0.1.2 pool/impl#[Builder][Default]default().().namerust-analyzer cargo threadfin 0.1.2 pool/impl#[Builder]name().("common-pool")
60 }