Coverage Report

Created: 2026-07-21 15:28

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
18
use nativelink_util::evicting_map;
19
use nativelink_util::store_trait::{RemoveCallback, StoreKey};
20
21
// Generic struct to hold a RemoveCallback ref for the purposes
22
// of a RemoveStateCallback call
23
#[derive(Debug)]
24
pub struct RemoveCallbackHolder {
25
    callback: RemoveCallback,
26
}
27
28
impl RemoveCallbackHolder {
29
103
    pub fn new(callback: RemoveCallback) -> Self {
30
103
        Self { callback }
31
103
    }
32
}
33
34
impl<'a, Q> evicting_map::RemoveItemCallback<Q> for RemoveCallbackHolder
35
where
36
    Q: Borrow<StoreKey<'a>>,
37
{
38
15
    fn callback(&self, store_key: &Q) -> Pin<Box<dyn Future<Output = ()> + Send>> {
39
15
        let callback = self.callback.clone();
40
15
        let store_key: &StoreKey<'_> = Borrow::<StoreKey<'_>>::borrow(store_key);
41
15
        let store_key = store_key.borrow().into_owned();
42
15
        Box::pin(async move { callback.callback(store_key).await })
43
15
    }
44
}