1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::env;
use std::path::PathBuf;
#[derive(Debug)]
pub struct Context<'a> {
invocation_id: &'a str,
function_id: &'a str,
name: &'a str,
}
impl<'a> Context<'a> {
pub fn new(invocation_id: &'a str, function_id: &'a str, name: &'a str) -> Self {
Context {
invocation_id,
function_id,
name,
}
}
pub fn invocation_id(&self) -> &str {
self.invocation_id
}
pub fn function_id(&self) -> &str {
self.function_id
}
pub fn function_name(&self) -> &str {
self.name
}
pub fn function_directory(&self) -> Option<PathBuf> {
self.app_directory().map(|p| p.join(self.name))
}
pub fn app_directory(&self) -> Option<PathBuf> {
env::current_exe()
.map(|p| p.parent().map(|p| p.to_owned()))
.ok()
.unwrap_or(None)
}
}