Coverage Report

Created: 2025-10-30 00:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/nativelink-store/src/callback_utils.rs
Line
Count
Source
1
// Copyright 2025 The NativeLink Authors. All rights reserved.
2
//
3
// Licensed under the Functional Source License, Version 1.1, Apache 2.0 Future License (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//    See LICENSE file for details
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
use core::borrow::Borrow;
16
use core::pin::Pin;
17
use std::sync::Arc;
18
19
use nativelink_util::evicting_map;
20
use nativelink_util::store_trait::{RemoveItemCallback, StoreKey};
21
22
// Generic struct to hold a RemoveItemCallback ref for the purposes
23
// of a RemoveStateCallback call
24
#[derive(Debug)]
25
pub struct RemoveItemCallbackHolder {
26
    callback: Arc<dyn RemoveItemCallback>,
27
}
28
29
impl RemoveItemCallbackHolder {
30
5
    pub fn new(callback: Arc<dyn RemoveItemCallback>) -> Self {
31
5
        Self { callback }
32
5
    }
33
}
34
35
impl<'a, Q> evicting_map::RemoveItemCallback<Q> for RemoveItemCallbackHolder
36
where
37
    Q: Borrow<StoreKey<'a>>,
38
{
39
2
    fn callback(&self, store_key: &Q) -> Pin<Box<dyn Future<Output = ()> + Send>> {
40
2
        let callback = self.callback.clone();
41
2
        let store_key: &StoreKey<'_> = Borrow::<StoreKey<'_>>::borrow(store_key);
42
2
        let store_key = store_key.borrow().into_owned();
43
2
        Box::pin(async move { callback.callback(store_key).await })
44
2
    }
45
}