onig/
match_param.rs
1use std::os::raw::{c_uint, c_ulong};
7
8pub struct MatchParam {
10 raw: *mut onig_sys::OnigMatchParam,
11}
12
13impl MatchParam {
14 pub fn set_match_stack_limit(&mut self, limit: u32) {
16 unsafe {
17 onig_sys::onig_set_match_stack_limit_size_of_match_param(self.raw, limit as c_uint);
18 }
19 }
20
21 pub fn set_retry_limit_in_match(&mut self, limit: u32) {
23 unsafe {
24 onig_sys::onig_set_retry_limit_in_match_of_match_param(self.raw, c_ulong::from(limit));
25 }
26 }
27
28 pub fn as_raw(&self) -> *mut onig_sys::OnigMatchParam {
30 self.raw
31 }
32}
33
34impl Default for MatchParam {
35 fn default() -> Self {
36 let raw = unsafe {
37 let new = onig_sys::onig_new_match_param();
38 onig_sys::onig_initialize_match_param(new);
39 new
40 };
41 MatchParam { raw }
42 }
43}
44
45impl Drop for MatchParam {
46 fn drop(&mut self) {
47 unsafe {
48 onig_sys::onig_free_match_param(self.raw);
49 }
50 }
51}
52
53#[cfg(test)]
54mod test {
55
56 use super::*;
57
58 #[test]
59 pub fn create_default_match_param() {
60 let _mp = MatchParam::default();
61 }
62
63 #[test]
64 pub fn set_max_stack_size_limit() {
65 let mut mp = MatchParam::default();
66 mp.set_match_stack_limit(1000);
67 }
68
69 #[test]
70 pub fn set_retry_limit_in_match() {
71 let mut mp = MatchParam::default();
72 mp.set_retry_limit_in_match(1000);
73 }
74}