redis_watcher/
options.rs

1// Copyright 2025 The Casbin Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use uuid::Uuid;
16
17/// Configuration options for the Redis watcher
18/// This mirrors the Go version's WatcherOptions structure
19#[derive(Debug, Clone)]
20pub struct WatcherOptions {
21    /// Redis channel for pub/sub
22    pub channel: String,
23
24    /// Whether to ignore messages from self
25    pub ignore_self: bool,
26
27    /// Local instance ID
28    pub local_id: String,
29}
30
31impl Default for WatcherOptions {
32    fn default() -> Self {
33        Self {
34            channel: "/casbin".to_string(),
35            ignore_self: false,
36            local_id: Uuid::new_v4().to_string(),
37        }
38    }
39}
40
41impl WatcherOptions {
42    /// Create new WatcherOptions with defaults
43    pub fn new() -> Self {
44        Self::default()
45    }
46
47    /// Set the Redis pub/sub channel
48    pub fn with_channel(mut self, channel: String) -> Self {
49        self.channel = channel;
50        self
51    }
52
53    /// Set whether to ignore self messages
54    pub fn with_ignore_self(mut self, ignore_self: bool) -> Self {
55        self.ignore_self = ignore_self;
56        self
57    }
58
59    /// Set local instance ID
60    pub fn with_local_id(mut self, local_id: String) -> Self {
61        self.local_id = local_id;
62        self
63    }
64}