Skip to content

Commit 850ab0a

Browse files
committed
Use async fn in trait.
1 parent 255164a commit 850ab0a

File tree

18 files changed

+149
-351
lines changed

18 files changed

+149
-351
lines changed

samply-api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct ExampleHelper {
5757
artifact_directory: std::path::PathBuf,
5858
}
5959

60-
impl<'h> FileAndPathHelper<'h> for ExampleHelper {
60+
impl FileAndPathHelper for ExampleHelper {
6161
type F = Vec<u8>;
6262
type FL = ExampleFileLocation;
6363
type OpenFileFuture = std::pin::Pin<

samply-api/src/asm/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ enum AsmError {
3939
FileIO(#[from] FileAndPathHelperError),
4040
}
4141

42-
pub struct AsmApi<'a, 'h: 'a, H: FileAndPathHelper<'h>> {
43-
symbol_manager: &'a SymbolManager<'h, H>,
42+
pub struct AsmApi<'a, H: FileAndPathHelper> {
43+
symbol_manager: &'a SymbolManager<H>,
4444
}
4545

46-
impl<'a, 'h: 'a, H: FileAndPathHelper<'h>> AsmApi<'a, 'h, H> {
46+
impl<'a, H: FileAndPathHelper> AsmApi<'a, H> {
4747
/// Create an [`AsmApi`] instance which uses the provided [`SymbolManager`].
48-
pub fn new(symbol_manager: &'a SymbolManager<'h, H>) -> Self {
48+
pub fn new(symbol_manager: &'a SymbolManager<H>) -> Self {
4949
Self { symbol_manager }
5050
}
5151

samply-api/src/lib.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//! let helper = ExampleHelper {
2626
//! artifact_directory: this_dir.join("..").join("fixtures").join("win64-ci")
2727
//! };
28-
//! let symbol_manager = SymbolManager::with_helper(&helper);
28+
//! let symbol_manager = SymbolManager::with_helper(helper);
2929
//! let api = samply_api::Api::new(&symbol_manager);
3030
//!
3131
//! api.query_api(
@@ -53,12 +53,9 @@
5353
//! artifact_directory: std::path::PathBuf,
5454
//! }
5555
//!
56-
//! impl<'h> FileAndPathHelper<'h> for ExampleHelper {
56+
//! impl FileAndPathHelper for ExampleHelper {
5757
//! type F = Vec<u8>;
5858
//! type FL = ExampleFileLocation;
59-
//! type OpenFileFuture = std::pin::Pin<
60-
//! Box<dyn OptionallySendFuture<Output = FileAndPathHelperResult<Self::F>> + 'h>,
61-
//! >;
6259
//!
6360
//! fn get_candidate_paths_for_debug_file(
6461
//! &self,
@@ -93,17 +90,11 @@
9390
//! Ok(vec![])
9491
//! }
9592
//!
96-
//! fn load_file(
97-
//! &'h self,
93+
//! async fn load_file(
94+
//! &self,
9895
//! location: ExampleFileLocation,
99-
//! ) -> std::pin::Pin<
100-
//! Box<dyn OptionallySendFuture<Output = FileAndPathHelperResult<Self::F>> + 'h>,
101-
//! > {
102-
//! async fn load_file_impl(path: std::path::PathBuf) -> FileAndPathHelperResult<Vec<u8>> {
103-
//! Ok(std::fs::read(&path)?)
104-
//! }
105-
//!
106-
//! Box::pin(load_file_impl(location.0))
96+
//! ) -> FileAndPathHelperResult<Self::F> {
97+
//! Ok(std::fs::read(&location.0)?)
10798
//! }
10899
//! }
109100
//!
@@ -164,13 +155,13 @@ pub(crate) fn to_debug_id(breakpad_id: &str) -> Result<DebugId, samply_symbols::
164155
}
165156

166157
#[derive(Clone, Copy)]
167-
pub struct Api<'a, 'h: 'a, H: FileAndPathHelper<'h>> {
168-
symbol_manager: &'a SymbolManager<'h, H>,
158+
pub struct Api<'a, H: FileAndPathHelper> {
159+
symbol_manager: &'a SymbolManager<H>,
169160
}
170161

171-
impl<'a, 'h: 'a, H: FileAndPathHelper<'h>> Api<'a, 'h, H> {
162+
impl<'a, H: FileAndPathHelper> Api<'a, H> {
172163
/// Create a [`Api`] instance which uses the provided [`SymbolManager`].
173-
pub fn new(symbol_manager: &'a SymbolManager<'h, H>) -> Self {
164+
pub fn new(symbol_manager: &'a SymbolManager<H>) -> Self {
174165
Self { symbol_manager }
175166
}
176167

samply-api/src/source/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ enum SourceError {
2525
FileAndPathHelperError(#[from] FileAndPathHelperError),
2626
}
2727

28-
pub struct SourceApi<'a, 'h: 'a, H: FileAndPathHelper<'h>> {
29-
symbol_manager: &'a SymbolManager<'h, H>,
28+
pub struct SourceApi<'a, H: FileAndPathHelper> {
29+
symbol_manager: &'a SymbolManager<H>,
3030
}
3131

32-
impl<'a, 'h: 'a, H: FileAndPathHelper<'h>> SourceApi<'a, 'h, H> {
32+
impl<'a, H: FileAndPathHelper> SourceApi<'a, H> {
3333
/// Create a [`SourceApi`] instance which uses the provided [`SymbolManager`].
34-
pub fn new(symbol_manager: &'a SymbolManager<'h, H>) -> Self {
34+
pub fn new(symbol_manager: &'a SymbolManager<H>) -> Self {
3535
Self { symbol_manager }
3636
}
3737

samply-api/src/symbolicate/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use looked_up_addresses::{AddressResults, LookedUpAddresses};
1212
use request_json::Lib;
1313
use serde_json::json;
1414

15-
pub struct SymbolicateApi<'a, 'h: 'a, H: FileAndPathHelper<'h>> {
16-
symbol_manager: &'a SymbolManager<'h, H>,
15+
pub struct SymbolicateApi<'a, H: FileAndPathHelper> {
16+
symbol_manager: &'a SymbolManager<H>,
1717
}
1818

19-
impl<'a, 'h: 'a, H: FileAndPathHelper<'h>> SymbolicateApi<'a, 'h, H> {
19+
impl<'a, H: FileAndPathHelper> SymbolicateApi<'a, H> {
2020
/// Create a [`SymbolicateApi`] instance which uses the provided [`SymbolManager`].
21-
pub fn new(symbol_manager: &'a SymbolManager<'h, H>) -> Self {
21+
pub fn new(symbol_manager: &'a SymbolManager<H>) -> Self {
2222
Self { symbol_manager }
2323
}
2424

samply-api/tests/integration_tests/main.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,26 @@ use samply_api::samply_symbols;
44
use samply_api::Api;
55
use samply_symbols::{
66
CandidatePathInfo, FileAndPathHelper, FileAndPathHelperResult, FileLocation, LibraryInfo,
7-
OptionallySendFuture, SymbolManager,
7+
SymbolManager,
88
};
99

1010
use std::fs::File;
1111
use std::io::{Read, Write};
1212
use std::path::PathBuf;
13-
use std::pin::Pin;
1413

1514
pub async fn query_api(request_url: &str, request_json: &str, symbol_directory: PathBuf) -> String {
1615
let helper = Helper { symbol_directory };
17-
let symbol_manager = SymbolManager::with_helper(&helper);
16+
let symbol_manager = SymbolManager::with_helper(helper);
1817
let api = Api::new(&symbol_manager);
1918
api.query_api(request_url, request_json).await
2019
}
2120
struct Helper {
2221
symbol_directory: PathBuf,
2322
}
2423

25-
impl<'h> FileAndPathHelper<'h> for Helper {
24+
impl FileAndPathHelper for Helper {
2625
type F = memmap2::Mmap;
2726
type FL = FileLocationType;
28-
type OpenFileFuture =
29-
Pin<Box<dyn OptionallySendFuture<Output = FileAndPathHelperResult<Self::F>> + 'h>>;
3027

3128
fn get_candidate_paths_for_debug_file(
3229
&self,
@@ -95,16 +92,7 @@ impl<'h> FileAndPathHelper<'h> for Helper {
9592
])
9693
}
9794

98-
fn load_file(
99-
&'h self,
100-
location: FileLocationType,
101-
) -> Pin<Box<dyn OptionallySendFuture<Output = FileAndPathHelperResult<Self::F>> + 'h>> {
102-
async fn load_file_impl(path: PathBuf) -> FileAndPathHelperResult<memmap2::Mmap> {
103-
eprintln!("Reading file {:?}", &path);
104-
let file = File::open(&path)?;
105-
Ok(unsafe { memmap2::MmapOptions::new().map(&file)? })
106-
}
107-
95+
async fn load_file(&self, location: FileLocationType) -> FileAndPathHelperResult<Self::F> {
10896
let mut path = location.0;
10997

11098
if !path.starts_with(&self.symbol_directory) {
@@ -122,7 +110,9 @@ impl<'h> FileAndPathHelper<'h> for Helper {
122110
}
123111
}
124112

125-
Box::pin(load_file_impl(path))
113+
eprintln!("Reading file {:?}", &path);
114+
let file = File::open(&path)?;
115+
Ok(unsafe { memmap2::MmapOptions::new().map(&file)? })
126116
}
127117

128118
fn get_candidate_paths_for_binary(

samply-symbols/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct ExampleHelper {
134134
artifact_directory: std::path::PathBuf,
135135
}
136136

137-
impl<'h> FileAndPathHelper<'h> for ExampleHelper {
137+
impl FileAndPathHelper for ExampleHelper {
138138
type F = Vec<u8>;
139139
type FL = ExampleFileLocation;
140140
type OpenFileFuture = std::pin::Pin<

samply-symbols/src/elf.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use crate::symbol_map::{
1111
use crate::symbol_map_object::{FunctionAddressesComputer, ObjectSymbolMapDataMid};
1212
use crate::{debug_id_for_object, ElfBuildId};
1313

14-
pub async fn load_symbol_map_for_elf<'h, T, FL, H>(
14+
pub async fn load_symbol_map_for_elf<T, FL, H>(
1515
file_location: FL,
1616
file_contents: FileContentsWrapper<T>,
1717
file_kind: FileKind,
18-
helper: &'h H,
18+
helper: &H,
1919
) -> Result<SymbolMap<FL>, Error>
2020
where
2121
T: FileContents + 'static,
22-
H: FileAndPathHelper<'h, F = T, FL = FL>,
22+
H: FileAndPathHelper<F = T, FL = FL>,
2323
FL: FileLocation,
2424
{
2525
let elf_file =
@@ -51,14 +51,14 @@ where
5151
Ok(SymbolMap::new(file_location, Box::new(symbol_map)))
5252
}
5353

54-
async fn try_to_get_symbol_map_from_debug_link<'h, 'data, H, R, FL>(
54+
async fn try_to_get_symbol_map_from_debug_link<'data, H, R, FL>(
5555
original_file_location: &H::FL,
5656
elf_file: &File<'data, R>,
5757
file_kind: FileKind,
58-
helper: &'h H,
58+
helper: &H,
5959
) -> Option<SymbolMap<FL>>
6060
where
61-
H: FileAndPathHelper<'h, FL = FL>,
61+
H: FileAndPathHelper<FL = FL>,
6262
R: ReadRef<'data>,
6363
FL: FileLocation,
6464
{
@@ -87,16 +87,16 @@ where
8787
None
8888
}
8989

90-
async fn get_symbol_map_for_debug_link_candidate<'h, H, FL>(
90+
async fn get_symbol_map_for_debug_link_candidate<H, FL>(
9191
original_file_location: &FL,
9292
path: &FL,
9393
debug_id: DebugId,
9494
expected_crc: u32,
9595
file_kind: FileKind,
96-
helper: &'h H,
96+
helper: &H,
9797
) -> Result<SymbolMap<FL>, Error>
9898
where
99-
H: FileAndPathHelper<'h, FL = FL>,
99+
H: FileAndPathHelper<FL = FL>,
100100
FL: FileLocation,
101101
{
102102
let file_contents = helper
@@ -217,13 +217,13 @@ fn compute_debug_link_crc_of_file_contents<T: FileContents>(
217217
Ok(computer.0)
218218
}
219219

220-
async fn try_to_load_supplementary_file<'h, 'data, H, F, R>(
220+
async fn try_to_load_supplementary_file<'data, H, F, R>(
221221
original_file_location: &H::FL,
222222
elf_file: &File<'data, R>,
223-
helper: &'h H,
223+
helper: &H,
224224
) -> Option<FileContentsWrapper<F>>
225225
where
226-
H: FileAndPathHelper<'h, F = F>,
226+
H: FileAndPathHelper<F = F>,
227227
R: ReadRef<'data>,
228228
F: FileContents + 'static,
229229
{

samply-symbols/src/external_file.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use crate::shared::{
1313
FileContentsWrapper, FileLocation, FrameDebugInfo, MultiArchDisambiguator, RangeReadRef,
1414
};
1515

16-
pub async fn load_external_file<'h, H>(
17-
helper: &'h H,
16+
pub async fn load_external_file<H>(
17+
helper: &H,
1818
original_file_location: &H::FL,
1919
external_file_ref: &ExternalFileRef,
2020
) -> Result<ExternalFileSymbolMap, Error>
2121
where
22-
H: FileAndPathHelper<'h>,
22+
H: FileAndPathHelper,
2323
{
2424
let file = helper
2525
.load_file(

0 commit comments

Comments
 (0)