gquintard / varnish-rs

Rust bindings for the Varnish Cache project
BSD 3-Clause "New" or "Revised" License
23 stars 4 forks source link

API redesign ideas: context, backend and delivery filters, ... #76

Open nyurik opened 2 months ago

nyurik commented 2 months ago

Some basic ideas, all subject to discussion, with some open questions...

Context

Filters

impl VarnishContext {
  pub fn register_delivery_filter(&mut self, instance: impl VDP) -> Result<(), VarnishError> {...}
  pub fn unregister_deliver_filter(&mut self, ???) -> Result<(), VarnishError> {...}
  pub fn register_backend_filter(&mut self, instance: impl VFP) -> Result<(), VarnishError> {...}
  pub fn unregister_backend_filter(&mut self, ???) -> Result<(), VarnishError> {...}
}

Logging

impl Logger {
  pub fn log(level: LogLevel, msg: &str) {...}
}

// Also define a few format!-like macros:  fail!(logger, "...", ...),  error!(...),  and a few others.

// User function
fn user_fn(log: &Logger) {
  info!(log, "Something cool is {var1} or {var2}");
}

Workspace

Workspace is always exclusive to the call, so perhaps allow user to request it (why?) The question of course is what benefit a user can get by having a direct reference (performance?).

fn user_fn(ws: &mut Workspace) {
  // TODO: use cases to justify this
}
nyurik commented 1 month ago

The workspace part has been implemented in #97