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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::marker::PhantomData;
use anyhow::Error;
use crate::context_stack::ContextStack;
use crate::context_stack::DummyContextStack;
pub trait RequestContext {
type ContextStack: ContextStack;
type Name: ?Sized;
fn get_context_stack(
&self,
service_name: &'static Self::Name,
fn_name: &'static Self::Name,
) -> Result<Self::ContextStack, Error>;
fn set_user_exception_header(&self, ex_type: &str, ex_reason: &str) -> Result<(), Error>;
}
pub struct DummyRequestContext<Name: ?Sized, Buffer> {
_phantom: PhantomData<(Buffer, Name)>,
}
impl<Name: ?Sized, Buffer> DummyRequestContext<Name, Buffer> {
pub fn new() -> Self {
Self {
_phantom: PhantomData,
}
}
}
impl<Name: ?Sized, Buffer> RequestContext for DummyRequestContext<Name, Buffer> {
type ContextStack = crate::context_stack::DummyContextStack<Name, Buffer>;
type Name = Name;
fn get_context_stack(
&self,
_service_name: &Self::Name,
_fn_name: &Self::Name,
) -> Result<Self::ContextStack, Error> {
Ok(DummyContextStack::new())
}
fn set_user_exception_header(&self, _ex_type: &str, _ex_reason: &str) -> Result<(), Error> {
Ok(())
}
}
fn _assert_context_stack(_: &impl RequestContext) {}
#[test]
fn check_unsized() {
_assert_context_stack(&DummyRequestContext::<std::ffi::CStr, Vec<u8>>::new());
}