Skip to content

Commit 4f36bf1

Browse files
fix(docs): make doc tests compilable with cargo test --doc
Signed-off-by: Anton Engelhardt <[email protected]>
1 parent 9eaac20 commit 4f36bf1

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ build = "build.rs"
1414
hashbrown = "0.14"
1515
log = "0.4"
1616

17+
[dev-dependencies]
18+
serde = { version = "1.0.210", features = ["derive"] }
19+
serde_json = "1.0.128"
20+
1721
[profile.release]
1822
lto = true
1923
opt-level = 3

src/traits.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ pub trait Context {
131131
///
132132
/// If `num_headers` is 0, then the HTTP call failed.
133133
///
134-
/// All headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header(name)`.
134+
/// All headers can be retrieved using `self.get_http_call_response_headers()` or individually `self.get_http_call_response_header(name)`.
135135
///
136-
/// All trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer(name)`.
136+
/// All trailers can be retrieved using `self.get_http_call_response_trailers()` or individually `self.get_http_call_response_trailer(name)`.
137137
///
138138
/// # Arguments
139139
///
@@ -365,11 +365,13 @@ pub trait RootContext: Context {
365365
/// serde_json::from_slice::<MyVmConfiguration>(&vm_configuration).unwrap();
366366
///
367367
/// // Do something with the parsed vm configuration
368-
/// debug!("vm_configuration: {:?}", parsed_vm_configuration)
368+
/// debug!("vm_configuration: {:?}", parsed_vm_configuration);
369369
///
370370
/// true
371371
/// }
372372
/// }
373+
///
374+
/// # impl Context for MyRootContext {}
373375
/// ```
374376
fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool {
375377
true
@@ -404,11 +406,13 @@ pub trait RootContext: Context {
404406
/// serde_json::from_slice::<MyVmConfiguration>(&vm_configuration).unwrap();
405407
///
406408
/// // Do something with the parsed vm configuration
407-
/// debug!("vm_configuration: {:?}", parsed_vm_configuration)
409+
/// debug!("vm_configuration: {:?}", parsed_vm_configuration);
408410
///
409411
/// true
410412
/// }
411413
/// }
414+
///
415+
/// # impl Context for MyRootContext {}
412416
/// ```
413417
fn get_vm_configuration(&self) -> Option<Bytes> {
414418
hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap()
@@ -448,11 +452,13 @@ pub trait RootContext: Context {
448452
/// serde_json::from_slice::<MyPluginConfiguration>(&plugin_configuration).unwrap();
449453
///
450454
/// // Do something with the parsed plugin configuration
451-
/// debug!("plugin_configuration: {:?}", parsed_plugin_configuration)
455+
/// debug!("plugin_configuration: {:?}", parsed_plugin_configuration);
452456
///
453457
/// true
454458
/// }
455459
/// }
460+
///
461+
/// # impl Context for MyRootContext {}
456462
/// ```
457463
fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool {
458464
true
@@ -487,11 +493,13 @@ pub trait RootContext: Context {
487493
/// serde_json::from_slice::<MyPluginConfiguration>(&plugin_configuration).unwrap();
488494
///
489495
/// // Do something with the parsed plugin configuration
490-
/// debug!("plugin_configuration: {:?}", parsed_plugin_configuration)
496+
/// debug!("plugin_configuration: {:?}", parsed_plugin_configuration);
491497
///
492498
/// true
493499
/// }
494500
/// }
501+
///
502+
/// # impl Context for MyRootContext {}
495503
/// ```
496504
fn get_plugin_configuration(&self) -> Option<Bytes> {
497505
hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap()
@@ -525,6 +533,8 @@ pub trait RootContext: Context {
525533
/// info!("tick!")
526534
/// }
527535
/// }
536+
///
537+
/// # impl Context for MyRootContext {}
528538
/// ```
529539
fn set_tick_period(&self, period: Duration) {
530540
hostcalls::set_tick_period(period).unwrap()
@@ -556,6 +566,8 @@ pub trait RootContext: Context {
556566
/// info!("tick!")
557567
/// }
558568
/// }
569+
///
570+
/// # impl Context for MyRootContext {}
559571
/// ```
560572
fn on_tick(&mut self) {}
561573

@@ -671,6 +683,8 @@ pub trait HttpContext: Context {
671683
/// Action::Continue
672684
/// }
673685
/// }
686+
///
687+
/// # impl Context for MyPlugin {}
674688
/// ```
675689
fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
676690
Action::Continue
@@ -702,6 +716,8 @@ pub trait HttpContext: Context {
702716
/// Action::Continue
703717
/// }
704718
/// }
719+
///
720+
/// # impl Context for MyPlugin {}
705721
/// ```
706722
fn get_http_request_headers(&self) -> Vec<(String, String)> {
707723
hostcalls::get_map(MapType::HttpRequestHeaders).unwrap()
@@ -732,7 +748,7 @@ pub trait HttpContext: Context {
732748
/// # Example
733749
///
734750
/// ```rust
735-
/// use proxy_wasm::traits:*;
751+
/// use proxy_wasm::traits::*;
736752
/// use proxy_wasm::types::*;
737753
/// use log::debug;
738754
///
@@ -749,6 +765,8 @@ pub trait HttpContext: Context {
749765
/// Action::Continue
750766
/// }
751767
/// }
768+
///
769+
/// # impl Context for MyPlugin {}
752770
/// ```
753771
fn get_http_request_header(&self, name: &str) -> Option<String> {
754772
hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap()
@@ -788,6 +806,8 @@ pub trait HttpContext: Context {
788806
/// Action::Continue
789807
/// }
790808
/// }
809+
///
810+
/// # impl Context for MyPlugin {}
791811
/// ```
792812
fn add_http_request_header(&self, name: &str, value: &str) {
793813
hostcalls::add_map_value(MapType::HttpRequestHeaders, name, value).unwrap()
@@ -1004,6 +1024,8 @@ pub trait HttpContext: Context {
10041024
/// Action::Pause
10051025
/// }
10061026
/// }
1027+
///
1028+
/// # impl Context for MyPlugin {}
10071029
/// ```
10081030
fn send_http_response(
10091031
&self,

0 commit comments

Comments
 (0)