Skip to content

Commit a018fb3

Browse files
committed
replace ToAnyParam with Into<Term> in macro calls
This removes the possibility to provide a public key where a term is expected and leverages a standard trait instead of a custom one
1 parent 87c09fa commit a018fb3

File tree

4 files changed

+8
-36
lines changed

4 files changed

+8
-36
lines changed

biscuit-auth/src/token/builder/check.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::{
1111
error, PublicKey,
1212
};
1313

14-
#[cfg(feature = "datalog-macro")]
15-
use super::ToAnyParam;
1614
use super::{display_rule_body, Convert, Rule, Term};
1715

1816
/// Builder for a Biscuit check
@@ -98,17 +96,12 @@ impl Check {
9896
}
9997

10098
#[cfg(feature = "datalog-macro")]
101-
pub fn set_macro_param<T: ToAnyParam>(
99+
pub fn set_macro_param<T: Into<Term>>(
102100
&mut self,
103101
name: &str,
104102
param: T,
105103
) -> Result<(), error::Token> {
106-
use super::AnyParam;
107-
108-
match param.to_any_param() {
109-
AnyParam::Term(t) => self.set_lenient(name, t),
110-
AnyParam::PublicKey(p) => self.set_scope_lenient(name, p),
111-
}
104+
self.set_lenient(name, param.into())
112105
}
113106

114107
// TODO maybe introduce a conversion trait to support refs, multiple values, non-pk scopes

biscuit-auth/src/token/builder/fact.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::{
1111
error,
1212
};
1313

14-
#[cfg(feature = "datalog-macro")]
15-
use super::ToAnyParam;
1614
use super::{Convert, Predicate, Term};
1715

1816
/// Builder for a Datalog fact
@@ -115,17 +113,12 @@ impl Fact {
115113
}
116114

117115
#[cfg(feature = "datalog-macro")]
118-
pub fn set_macro_param<T: ToAnyParam>(
116+
pub fn set_macro_param<T: Into<Term>>(
119117
&mut self,
120118
name: &str,
121119
param: T,
122120
) -> Result<(), error::Token> {
123-
use super::AnyParam;
124-
125-
match param.to_any_param() {
126-
AnyParam::Term(t) => self.set_lenient(name, t),
127-
AnyParam::PublicKey(_) => Ok(()),
128-
}
121+
self.set_lenient(name, param.into())
129122
}
130123

131124
pub(super) fn apply_parameters(&mut self) {

biscuit-auth/src/token/builder/policy.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use nom::Finish;
88

99
use crate::{error, PublicKey};
1010

11-
#[cfg(feature = "datalog-macro")]
12-
use super::ToAnyParam;
1311
use super::{display_rule_body, Rule, Term};
1412

1513
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -91,17 +89,12 @@ impl Policy {
9189
}
9290

9391
#[cfg(feature = "datalog-macro")]
94-
pub fn set_macro_param<T: ToAnyParam>(
92+
pub fn set_macro_param<T: Into<Term>>(
9593
&mut self,
9694
name: &str,
9795
param: T,
9896
) -> Result<(), error::Token> {
99-
use super::AnyParam;
100-
101-
match param.to_any_param() {
102-
AnyParam::Term(t) => self.set_lenient(name, t),
103-
AnyParam::PublicKey(p) => self.set_scope_lenient(name, p),
104-
}
97+
self.set_lenient(name, param.into())
10598
}
10699

107100
// TODO maybe introduce a conversion trait to support refs, multiple values, non-pk scopes

biscuit-auth/src/token/builder/rule.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::{
1111
error, PublicKey,
1212
};
1313

14-
#[cfg(feature = "datalog-macro")]
15-
use super::ToAnyParam;
1614
use super::{Convert, Expression, Predicate, Scope, Term};
1715

1816
/// Builder for a Datalog rule
@@ -245,17 +243,12 @@ impl Rule {
245243
}
246244

247245
#[cfg(feature = "datalog-macro")]
248-
pub fn set_macro_param<T: ToAnyParam>(
246+
pub fn set_macro_param<T: Into<Term>>(
249247
&mut self,
250248
name: &str,
251249
param: T,
252250
) -> Result<(), error::Token> {
253-
use super::AnyParam;
254-
255-
match param.to_any_param() {
256-
AnyParam::Term(t) => self.set_lenient(name, t),
257-
AnyParam::PublicKey(pubkey) => self.set_scope_lenient(name, pubkey),
258-
}
251+
self.set_lenient(name, param.into())
259252
}
260253

261254
// TODO maybe introduce a conversion trait to support refs, multiple values, non-pk scopes

0 commit comments

Comments
 (0)