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
use fastly_sys::fastly_purge as sys;
use anyhow::anyhow;
use crate::Error;
pub fn purge_surrogate_key(surrogate_key: &str) -> Result<(), Error> {
purge_surrogate_key_impl(surrogate_key, false)
}
pub fn soft_purge_surrogate_key(surrogate_key: &str) -> Result<(), Error> {
purge_surrogate_key_impl(surrogate_key, true)
}
fn purge_surrogate_key_impl(surrogate_key: &str, soft: bool) -> Result<(), Error> {
let mut options_mask = sys::PurgeOptionsMask::empty();
options_mask.set(sys::PurgeOptionsMask::SOFT_PURGE, soft);
let mut options = sys::PurgeOptions {
ret_buf_ptr: std::ptr::null_mut(),
ret_buf_len: 0,
ret_buf_nwritten_out: std::ptr::null_mut(),
};
unsafe {
sys::purge_surrogate_key(
surrogate_key.as_ptr(),
surrogate_key.len(),
options_mask,
&mut options,
)
}
.result()
.map_err(|e| anyhow!("purge error: {:?}", e))
}