---
source: varnish-macros/src/tests.rs
---
mod event3 {
#[allow(non_snake_case, unused_imports, unused_qualifications, unused_variables)]
#[allow(clippy::needless_question_mark, clippy::new_without_default)]
#[automatically_derived]
mod varnish_generated {
use std::ffi::{c_char, c_int, c_uint, c_void, CStr};
use std::ptr::null;
use varnish::ffi::{
VCL_BACKEND, VCL_BLOB, VCL_BOOL, VCL_DURATION, VCL_INT, VCL_IP, VCL_PROBE,
VCL_REAL, VCL_STRING, VCL_TIME, VCL_VOID, VMOD_ABI_Version, VclEvent,
vmod_data, vmod_priv, vrt_ctx, VMOD_PRIV_METHODS_MAGIC, vmod_priv_methods,
};
use varnish::vcl::{Ctx, IntoVCL, PerVclState, Workspace};
use super::*;
static PRIV_VCL_METHODS: vmod_priv_methods = vmod_priv_methods {
magic: VMOD_PRIV_METHODS_MAGIC,
type_: c"PerVcl".as_ptr(),
fini: Some(vmod_priv::on_fini_per_vcl::<PerVcl>),
};
unsafe extern "C" fn vmod_c_on_event(
__ctx: *mut vrt_ctx,
__vp: *mut vmod_priv,
__ev: VclEvent,
) -> VCL_INT {
let mut __ctx = Ctx::from_ptr(__ctx);
let mut __obj_per_vcl = (*__vp).take_per_vcl::<PerVcl>();
let mut __call_user_func = || -> Result<_, ::varnish::vcl::VclError> {
super::on_event(
&__ctx,
__ev,
&mut __obj_per_vcl.user_data,
&mut __ctx.raw.delivery_filters(&mut __obj_per_vcl.delivery_filters),
&mut __ctx.raw.fetch_filters(&mut __obj_per_vcl.fetch_filters),
)?;
Ok(VCL_INT(0))
};
let __result = __call_user_func();
(*__vp).put(__obj_per_vcl, &PRIV_VCL_METHODS);
__result
.unwrap_or_else(|err| {
__ctx.fail(err);
VCL_INT(1)
})
}
unsafe extern "C" fn vmod_c_access(__ctx: *mut vrt_ctx, vcl: *const vmod_priv) {
super::access(
vcl
.as_ref()
.and_then::<&PerVclState<_>, _>(|v| v.get_ref())
.and_then(|v| v.get_user_data()),
)
}
unsafe extern "C" fn vmod_c_Obj1__init(
__ctx: *mut vrt_ctx,
__objp: *mut *mut Obj1,
__vcl_name: *const c_char,
__vp: *mut vmod_priv,
) {
let mut __obj_per_vcl = (*__vp).take_per_vcl::<PerVcl>();
let __result = Box::new(super::Obj1::new(&mut __obj_per_vcl.user_data));
*__objp = Box::into_raw(__result);
(*__vp).put(__obj_per_vcl, &PRIV_VCL_METHODS);
}
unsafe extern "C" fn vmod_c_Obj1__fini(__objp: *mut *mut Obj1) {
drop(Box::from_raw(*__objp));
*__objp = ::std::ptr::null_mut();
}
unsafe extern "C" fn vmod_c_Obj1_obj_access(
__ctx: *mut vrt_ctx,
__obj: *const super::Obj1,
vcl: *const vmod_priv,
) {
let __obj = __obj.as_ref().unwrap();
__obj
.obj_access(
vcl
.as_ref()
.and_then::<&PerVclState<_>, _>(|v| v.get_ref())
.and_then(|v| v.get_user_data()),
)
}
unsafe extern "C" fn vmod_c_Obj2__init(
__ctx: *mut vrt_ctx,
__objp: *mut *mut Obj2,
__vcl_name: *const c_char,
__vp: *mut vmod_priv,
) {
let mut __ctx = Ctx::from_ptr(__ctx);
let mut __obj_per_vcl = (*__vp).take_per_vcl::<PerVcl>();
let __result = Box::new(
super::Obj2::new(
&mut __ctx.raw.delivery_filters(&mut __obj_per_vcl.delivery_filters),
),
);
*__objp = Box::into_raw(__result);
(*__vp).put(__obj_per_vcl, &PRIV_VCL_METHODS);
}
unsafe extern "C" fn vmod_c_Obj2__fini(__objp: *mut *mut Obj2) {
drop(Box::from_raw(*__objp));
*__objp = ::std::ptr::null_mut();
}
unsafe extern "C" fn vmod_c_Obj2_obj_access(
__ctx: *mut vrt_ctx,
__obj: *const super::Obj2,
) {
let __obj = __obj.as_ref().unwrap();
__obj.obj_access()
}
#[repr(C)]
pub struct VmodExports {
vmod_c_on_event: Option<
unsafe extern "C" fn(
__ctx: *mut vrt_ctx,
__vp: *mut vmod_priv,
__ev: VclEvent,
) -> VCL_INT,
>,
vmod_c_access: Option<
unsafe extern "C" fn(__ctx: *mut vrt_ctx, vcl: *const vmod_priv),
>,
vmod_c_Obj1__init: Option<
unsafe extern "C" fn(
__ctx: *mut vrt_ctx,
__objp: *mut *mut Obj1,
__vcl_name: *const c_char,
__vp: *mut vmod_priv,
),
>,
vmod_c_Obj1__fini: Option<unsafe extern "C" fn(__objp: *mut *mut Obj1)>,
vmod_c_Obj1_obj_access: Option<
unsafe extern "C" fn(
__ctx: *mut vrt_ctx,
__obj: *const super::Obj1,
vcl: *const vmod_priv,
),
>,
vmod_c_Obj2__init: Option<
unsafe extern "C" fn(
__ctx: *mut vrt_ctx,
__objp: *mut *mut Obj2,
__vcl_name: *const c_char,
__vp: *mut vmod_priv,
),
>,
vmod_c_Obj2__fini: Option<unsafe extern "C" fn(__objp: *mut *mut Obj2)>,
vmod_c_Obj2_obj_access: Option<
unsafe extern "C" fn(__ctx: *mut vrt_ctx, __obj: *const super::Obj2),
>,
}
pub static VMOD_EXPORTS: VmodExports = VmodExports {
vmod_c_on_event: Some(vmod_c_on_event),
vmod_c_access: Some(vmod_c_access),
vmod_c_Obj1__init: Some(vmod_c_Obj1__init),
vmod_c_Obj1__fini: Some(vmod_c_Obj1__fini),
vmod_c_Obj1_obj_access: Some(vmod_c_Obj1_obj_access),
vmod_c_Obj2__init: Some(vmod_c_Obj2__init),
vmod_c_Obj2__fini: Some(vmod_c_Obj2__fini),
vmod_c_Obj2_obj_access: Some(vmod_c_Obj2_obj_access),
};
#[allow(non_upper_case_globals)]
#[no_mangle]
pub static Vmod_event3_Data: vmod_data = vmod_data {
vrt_major: 0,
vrt_minor: 0,
file_id: c"65b49085a4dba9c1b453b7e82d61d20a705b516d4ab88c0875ecb5eb7807fbb6"
.as_ptr(),
name: c"event3".as_ptr(),
func_name: c"Vmod_vmod_event3_Func".as_ptr(),
func_len: ::std::mem::size_of::<VmodExports>() as c_int,
func: &VMOD_EXPORTS as *const _ as *const c_void,
abi: VMOD_ABI_Version.as_ptr(),
json: JSON.as_ptr(),
proto: null(),
vcs: c"".as_ptr(),
version: c"".as_ptr(),
};
const JSON: &CStr = c"(moved to @json.snap files)";
}
use varnish::vcl::{Ctx, DeliveryFilters, Event, FetchFilters};
use super::{Obj1, Obj2, PerVcl};
pub fn on_event(
ctx: &Ctx,
event: Event,
vcl: &mut Option<Box<PerVcl>>,
vdp: &mut DeliveryFilters,
vfp: &mut FetchFilters,
) -> Result<(), &'static str> {
Ok(())
}
pub fn access(vcl: Option<&PerVcl>) {}
impl Obj1 {
pub fn new(vcl: &mut Option<Box<PerVcl>>) -> Self {
Self
}
pub fn obj_access(&self, vcl: Option<&PerVcl>) {}
}
impl Obj2 {
pub fn new(vdp: &mut DeliveryFilters) -> Self {
Self
}
pub fn obj_access(&self) {}
}
}