Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trait order and type #37

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions examples/vmod_vdp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
varnish::boilerplate!();

use std::ffi::CStr;

use varnish::ffi;
use varnish::vcl::ctx::{Ctx, Event};
use varnish::vcl::processor::{new_vdp, InitResult, PushAction, PushResult, VDPCtx, VDP};
Expand All @@ -15,11 +17,6 @@ struct Flipper {

// implement the actual behavior of the VDP
impl VDP for Flipper {
// return our id, adding the NULL character to avoid confusing the C layer
fn name() -> &'static str {
"flipper\0"
}

// `new` is called when the VCL specifies "flipper" in `resp.filters`
// just return an default struct, thanks to the derive macro
fn new(_: &mut Ctx, _: &mut VDPCtx, _oc: *mut ffi::objcore) -> InitResult<Self> {
Expand All @@ -41,6 +38,11 @@ impl VDP for Flipper {
// send
ctx.push(act, &self.body)
}

// return our id
fn name() -> &'static CStr {
c"flipper"
}
}

pub unsafe fn event(
Expand Down
12 changes: 7 additions & 5 deletions examples/vmod_vfp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
varnish::boilerplate!();

use std::ffi::CStr;

use varnish::ffi;
use varnish::vcl::ctx::{Ctx, Event};
use varnish::vcl::processor::{new_vfp, InitResult, PullResult, VFPCtx, VFP};
Expand All @@ -12,11 +14,6 @@ struct Lower {}

// implement the actual behavior of the VFP
impl VFP for Lower {
// return our id, adding the NULL character to avoid confusing the C layer
fn name() -> &'static str {
"lower\0"
}

// `new` is called when the VCL specifies "lower" in `beresp.filters`
fn new(_: &mut Ctx, _: &mut VFPCtx) -> InitResult<Self> {
InitResult::Ok(Lower {})
Expand All @@ -36,6 +33,11 @@ impl VFP for Lower {
}
pull_res
}

// return our id, adding the NULL character to avoid confusing the C layer
fn name() -> &'static CStr {
c"lower"
}
}

pub unsafe fn event(
Expand Down
8 changes: 3 additions & 5 deletions src/vcl/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! *Note:* The rust wrapper here is pretty thin and the vmod writer will most probably need to have to
//! deal with the raw Varnish internals.

use std::ffi::{c_char, c_int, c_void};
use std::ffi::{c_char, c_int, c_void, CStr};
use std::ptr;

use crate::ffi;
Expand Down Expand Up @@ -68,7 +68,7 @@ where
/// The name of the processor.
///
/// **Note:** it must be NULL-terminated as it will be used directly as a C string.
fn name() -> &'static str;
fn name() -> &'static CStr;
}

pub unsafe extern "C" fn gen_vdp_init<T: VDP>(
Expand Down Expand Up @@ -196,9 +196,7 @@ where
/// The name of the processor.
///
/// **Note:** it must be NULL-terminated as it will be used directly as a C string.
fn name() -> &'static str {
unimplemented!()
}
fn name() -> &'static CStr;
}

unsafe extern "C" fn wrap_vfp_init<T: VFP>(
Expand Down
9 changes: 5 additions & 4 deletions vmod_test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
varnish::boilerplate!();

use std::ffi::CStr;
use std::io::Write;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::time::Duration;
Expand Down Expand Up @@ -162,17 +163,17 @@ struct VFPTest {

// Force a pass here to test to make sure that fini does not panic due to a null priv1 member
impl VFP for VFPTest {
fn name() -> &'static str {
"vfptest\0"
}

fn new(_: &mut Ctx, _: &mut VFPCtx) -> InitResult<Self> {
InitResult::Pass
}

fn pull(&mut self, _: &mut VFPCtx, _: &mut [u8]) -> PullResult {
PullResult::Err
}

fn name() -> &'static CStr {
c"vfptest"
}
}

pub unsafe fn event(
Expand Down