Skip to content

Commit 84b30b8

Browse files
committed
chore: add rustfmt.toml and dependabot, apply formatting
- Add rustfmt.toml aligned with kube-rs/kube style - Add dependabot.yml for automated dependency updates - Apply rustfmt to all source files
1 parent b11bf4a commit 84b30b8

27 files changed

Lines changed: 282 additions & 658 deletions

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
labels:
8+
- "dependencies"
9+
10+
- package-ecosystem: "cargo"
11+
directory: "/"
12+
schedule:
13+
interval: "weekly"
14+
labels:
15+
- "dependencies"

examples/basic.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ fn main() {
4747

4848
// IP / CIDR
4949
run(&ctx, "ip family", "ip('192.168.1.1').family()");
50-
run(
51-
&ctx,
52-
"cidr.ip()",
53-
"cidr('10.0.0.0/24').ip() == ip('10.0.0.0')",
54-
);
50+
run(&ctx, "cidr.ip()", "cidr('10.0.0.0/24').ip() == ip('10.0.0.0')");
5551
run(&ctx, "isIPv4", "isIPv4('192.168.1.1')");
5652
run(&ctx, "isCIDRv6", "isCIDRv6('fd00::/64')");
5753

examples/compiled_schema.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
//!
33
//! Run with: `cargo run --example compiled_schema --features validation`
44
5-
use kube_cel::compilation::compile_schema;
6-
use kube_cel::validation::validate_compiled;
5+
use kube_cel::{compilation::compile_schema, validation::validate_compiled};
76
use serde_json::json;
87

98
fn main() {

examples/timestamp_duration.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
//!
33
//! Run with: `cargo run --example timestamp_duration --features validation`
44
5-
use kube_cel::compilation::compile_schema;
6-
use kube_cel::validation::{validate, validate_compiled};
5+
use kube_cel::{
6+
compilation::compile_schema,
7+
validation::{validate, validate_compiled},
8+
};
79
use serde_json::json;
810

911
fn main() {

rustfmt.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://github.com/kube-rs/kube/issues/707
2+
style_edition = "2024"
3+
unstable_features = true
4+
overflow_delimited_expr = true
5+
newline_style = "Unix"
6+
imports_granularity = "Crate"
7+
reorder_impl_items = true
8+
blank_lines_upper_bound = 2
9+
comment_width = 110
10+
max_width = 110
11+
inline_attribute_width = 80

src/compilation.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ pub(crate) fn compile_schema_validations(
123123
rules
124124
.iter()
125125
.map(|raw| {
126-
let rule: Rule =
127-
serde_json::from_value(raw.clone()).map_err(CompilationError::InvalidRule)?;
126+
let rule: Rule = serde_json::from_value(raw.clone()).map_err(CompilationError::InvalidRule)?;
128127
compile_rule(&rule)
129128
})
130129
.collect()
@@ -155,10 +154,7 @@ impl CompiledSchema {
155154
/// Returns references to all compilation errors in this node's validations.
156155
#[must_use]
157156
pub fn compilation_errors(&self) -> Vec<&CompilationError> {
158-
self.validations
159-
.iter()
160-
.filter_map(|r| r.as_ref().err())
161-
.collect()
157+
self.validations.iter().filter_map(|r| r.as_ref().err()).collect()
162158
}
163159

164160
/// Returns `true` if any validation rule at this node failed to compile.

src/dispatch.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
//! both strings and lists), this module provides unified dispatch functions
66
//! that route to the correct implementation based on the runtime type of `this`.
77
8-
#[cfg(any(feature = "ip", feature = "lists"))]
9-
use std::sync::Arc;
8+
#[cfg(any(feature = "ip", feature = "lists"))] use std::sync::Arc;
109

11-
use cel::extractors::{Arguments, This};
12-
use cel::objects::Value;
13-
use cel::{Context, ExecutionError, ResolveResult};
10+
use cel::{
11+
Context, ExecutionError, ResolveResult,
12+
extractors::{Arguments, This},
13+
objects::Value,
14+
};
1415

1516
/// Register dispatch functions for names shared across multiple types or
1617
/// that override cel built-in functions. Registration order is independent
@@ -158,11 +159,8 @@ fn ip_dispatch(This(this): This<Value>, Arguments(args): Arguments) -> ResolveRe
158159
}
159160
},
160161
};
161-
let addr = crate::ip::parse_ip_addr(&s)
162-
.map_err(|e| ExecutionError::function_error("ip", e))?;
163-
Ok(Value::Opaque(std::sync::Arc::new(crate::ip::KubeIP::new(
164-
addr,
165-
))))
162+
let addr = crate::ip::parse_ip_addr(&s).map_err(|e| ExecutionError::function_error("ip", e))?;
163+
Ok(Value::Opaque(std::sync::Arc::new(crate::ip::KubeIP::new(addr))))
166164
}
167165
}
168166
}
@@ -209,8 +207,7 @@ fn builtin_string_fallback(this: Value) -> ResolveResult {
209207
))),
210208
Value::Timestamp(ref t) => Ok(Value::String(Arc::new(t.to_rfc3339()))),
211209
Value::Duration(ref d) => Ok(Value::String(Arc::new(format_cel_duration(
212-
d.num_nanoseconds()
213-
.unwrap_or(d.num_seconds() * 1_000_000_000),
210+
d.num_nanoseconds().unwrap_or(d.num_seconds() * 1_000_000_000),
214211
)))),
215212
_ => Err(ExecutionError::function_error(
216213
"string",
@@ -391,10 +388,7 @@ mod tests {
391388
#[test]
392389
#[cfg(feature = "ip")]
393390
fn test_string_float() {
394-
assert_eq!(
395-
eval("3.14.string()"),
396-
Value::String("3.14".to_string().into())
397-
);
391+
assert_eq!(eval("3.14.string()"), Value::String("3.14".to_string().into()));
398392
}
399393

400394
#[test]
@@ -409,10 +403,7 @@ mod tests {
409403
#[test]
410404
#[cfg(feature = "ip")]
411405
fn test_string_bytes() {
412-
assert_eq!(
413-
eval("b'abc'.string()"),
414-
Value::String("abc".to_string().into())
415-
);
406+
assert_eq!(eval("b'abc'.string()"), Value::String("abc".to_string().into()));
416407
}
417408

418409
#[test]

src/encoders.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
//! Provides `base64.decode` and `base64.encode` matching
44
//! `cel-go/ext/encoders.go`.
55
6-
use base64::Engine;
7-
use base64::engine::DecodePaddingMode;
8-
use base64::engine::general_purpose::{GeneralPurpose, GeneralPurposeConfig, STANDARD};
9-
use cel::objects::Value;
10-
use cel::{Context, ExecutionError, ResolveResult};
6+
use base64::{
7+
Engine,
8+
engine::{
9+
DecodePaddingMode,
10+
general_purpose::{GeneralPurpose, GeneralPurposeConfig, STANDARD},
11+
},
12+
};
13+
use cel::{Context, ExecutionError, ResolveResult, objects::Value};
1114
use std::sync::Arc;
1215

1316
/// Base64 decoder that accepts both padded and unpadded input (matching cel-go).

src/format.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
//! Provides printf-style `format()` function,
44
//! matching `cel-go/ext/strings.go` format implementation.
55
6-
use cel::extractors::This;
7-
use cel::objects::{Key, Value};
8-
use cel::{Context, ExecutionError, ResolveResult};
6+
use cel::{
7+
Context, ExecutionError, ResolveResult,
8+
extractors::This,
9+
objects::{Key, Value},
10+
};
911
use std::sync::Arc;
1012

1113
/// Register the format function.
@@ -277,10 +279,7 @@ fn format_hex(val: &Value, upper: bool, out: &mut String) -> Result<(), Executio
277279
_ => {
278280
return Err(ExecutionError::function_error(
279281
"format",
280-
format!(
281-
"%x requires int, uint, string, or bytes, got {:?}",
282-
val.type_of()
283-
),
282+
format!("%x requires int, uint, string, or bytes, got {:?}", val.type_of()),
284283
));
285284
}
286285
}
@@ -294,10 +293,7 @@ fn extract_float(val: &Value, verb: char) -> Result<f64, ExecutionError> {
294293
Value::UInt(n) => Ok(*n as f64),
295294
_ => Err(ExecutionError::function_error(
296295
"format",
297-
format!(
298-
"%{verb} requires float, int, or uint, got {:?}",
299-
val.type_of()
300-
),
296+
format!("%{verb} requires float, int, or uint, got {:?}", val.type_of()),
301297
)),
302298
}
303299
}
@@ -323,10 +319,7 @@ mod tests {
323319
#[test]
324320
fn test_format_s() {
325321
assert_eq!(eval_str("'hello %s'.format(['world'])"), "hello world");
326-
assert_eq!(
327-
eval_str("'%s is %s'.format(['age', 'number'])"),
328-
"age is number"
329-
);
322+
assert_eq!(eval_str("'%s is %s'.format(['age', 'number'])"), "age is number");
330323
}
331324

332325
#[test]

0 commit comments

Comments
 (0)