Skip to content

Commit ac396d7

Browse files
committed
chore: apply updated styling rules
1 parent 31c9905 commit ac396d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1455
-3425
lines changed

examples/src/bin/axum_middleware.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
//! curl -X DELETE http://localhost:3000/documents/readme
2121
//! ```
2222
23-
use std::env;
24-
use std::net::SocketAddr;
23+
use std::{env, net::SocketAddr};
2524

2625
use axum::{
26+
Router,
2727
extract::{Path, State},
2828
http::StatusCode,
2929
response::IntoResponse,
3030
routing::{delete, get},
31-
Router,
3231
};
3332
use inferadb::prelude::*;
3433

@@ -84,11 +83,7 @@ async fn view_document(
8483
let resource = format!("document:{doc_id}");
8584

8685
// Use require() pattern - converts denial to error
87-
state
88-
.vault
89-
.check(user_id, "view", &resource)
90-
.require()
91-
.await?;
86+
state.vault.check(user_id, "view", &resource).require().await?;
9287

9388
// User is authorized - return document content
9489
Ok(format!("Document content for: {doc_id}"))
@@ -103,11 +98,7 @@ async fn delete_document(
10398
let resource = format!("document:{doc_id}");
10499

105100
// Check authorization first
106-
state
107-
.vault
108-
.check(user_id, "delete", &resource)
109-
.require()
110-
.await?;
101+
state.vault.check(user_id, "delete", &resource).require().await?;
111102

112103
// User is authorized - delete the document
113104
Ok(format!("Deleted document: {doc_id}"))
@@ -157,7 +148,7 @@ impl IntoResponse for AppError {
157148
),
158149
)
159150
.into_response()
160-
}
151+
},
161152
AppError::InferaDb(err) => {
162153
// Map SDK errors to HTTP status codes
163154
let status = match err.kind() {
@@ -176,7 +167,7 @@ impl IntoResponse for AppError {
176167
};
177168

178169
(status, message).into_response()
179-
}
170+
},
180171
}
181172
}
182173
}

examples/src/bin/basic_check.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,18 @@ async fn main() -> Result<()> {
5353
// Policies can use context values for attribute-based decisions
5454
let allowed_with_context = vault
5555
.check("user:alice", "view", "document:confidential")
56-
.with_context(
57-
Context::new()
58-
.with("ip_address", "10.0.0.50")
59-
.with("mfa_verified", true),
60-
)
56+
.with_context(Context::new().with("ip_address", "10.0.0.50").with("mfa_verified", true))
6157
.await?;
6258

6359
println!("user:alice can view document:confidential (with MFA): {allowed_with_context}");
6460

6561
// The require() pattern - recommended for HTTP handlers
6662
// Converts denial (false) into Err(AccessDenied), integrates with ?
67-
match vault
68-
.check("user:alice", "delete", "document:readme")
69-
.require()
70-
.await
71-
{
63+
match vault.check("user:alice", "delete", "document:readme").require().await {
7264
Ok(()) => println!("user:alice can delete document:readme"),
7365
Err(AccessDenied { .. }) => {
7466
println!("user:alice cannot delete document:readme (access denied)")
75-
}
67+
},
7668
}
7769

7870
println!("\nExample complete!");

examples/src/bin/batch_operations.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,13 @@ async fn main() -> Result<()> {
9090
// Write returns a consistency token for read-after-write consistency
9191
let token = vault
9292
.relationships()
93-
.write(Relationship::new(
94-
"document:new-doc",
95-
"viewer",
96-
"user:charlie",
97-
))
93+
.write(Relationship::new("document:new-doc", "viewer", "user:charlie"))
9894
.await?;
9995

10096
println!(" Write returned consistency token: {}", token.value());
10197

10298
// After writing, the authorization check will reflect the new relationship
103-
let allowed = vault
104-
.check("user:charlie", "view", "document:new-doc")
105-
.await?;
99+
let allowed = vault.check("user:charlie", "view", "document:new-doc").await?;
106100

107101
println!(" user:charlie can view document:new-doc: {allowed}");
108102

@@ -115,11 +109,7 @@ async fn main() -> Result<()> {
115109
// Delete the test relationships
116110
vault
117111
.relationships()
118-
.delete(Relationship::new(
119-
"document:new-doc",
120-
"viewer",
121-
"user:charlie",
122-
))
112+
.delete(Relationship::new("document:new-doc", "viewer", "user:charlie"))
123113
.await?;
124114

125115
println!(" Deleted test relationship");

inferadb-derive/src/lib.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
use proc_macro::TokenStream;
4646
use proc_macro2::TokenStream as TokenStream2;
4747
use quote::quote;
48-
use syn::{parse_macro_input, Data, DeriveInput, Error, Fields, Ident, LitStr, Result};
48+
use syn::{Data, DeriveInput, Error, Fields, Ident, LitStr, Result, parse_macro_input};
4949

5050
/// Derive macro for implementing the `Resource` trait.
5151
///
@@ -183,27 +183,21 @@ fn find_id_field(data: &Data, attr_name: &str) -> Result<Ident> {
183183
return Err(Error::new(
184184
proc_macro2::Span::call_site(),
185185
"tuple structs are not supported",
186-
))
187-
}
186+
));
187+
},
188188
Fields::Unit => {
189189
return Err(Error::new(
190190
proc_macro2::Span::call_site(),
191191
"unit structs are not supported",
192-
))
193-
}
192+
));
193+
},
194194
},
195195
Data::Enum(_) => {
196-
return Err(Error::new(
197-
proc_macro2::Span::call_site(),
198-
"enums are not supported",
199-
))
200-
}
196+
return Err(Error::new(proc_macro2::Span::call_site(), "enums are not supported"));
197+
},
201198
Data::Union(_) => {
202-
return Err(Error::new(
203-
proc_macro2::Span::call_site(),
204-
"unions are not supported",
205-
))
206-
}
199+
return Err(Error::new(proc_macro2::Span::call_site(), "unions are not supported"));
200+
},
207201
};
208202

209203
for field in fields {

src/auth/credentials.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Credentials types for InferaDB authentication.
22
3-
use std::fmt;
4-
use std::sync::Arc;
3+
use std::{fmt, sync::Arc};
54

65
use super::Ed25519PrivateKey;
76

@@ -71,11 +70,7 @@ impl ClientCredentialsConfig {
7170
/// );
7271
/// ```
7372
pub fn new(client_id: impl Into<String>, private_key: Ed25519PrivateKey) -> Self {
74-
Self {
75-
client_id: client_id.into(),
76-
private_key,
77-
certificate_id: None,
78-
}
73+
Self { client_id: client_id.into(), private_key, certificate_id: None }
7974
}
8075

8176
/// Sets the certificate ID for certificate binding.
@@ -141,9 +136,7 @@ impl BearerCredentialsConfig {
141136
/// let config = BearerCredentialsConfig::new("eyJhbGciOiJFZERTQSI...");
142137
/// ```
143138
pub fn new(token: impl Into<String>) -> Self {
144-
Self {
145-
token: Arc::from(token.into()),
146-
}
139+
Self { token: Arc::from(token.into()) }
147140
}
148141

149142
/// Returns the bearer token.
@@ -154,9 +147,7 @@ impl BearerCredentialsConfig {
154147

155148
impl fmt::Debug for BearerCredentialsConfig {
156149
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157-
f.debug_struct("BearerCredentialsConfig")
158-
.field("token", &"[REDACTED]")
159-
.finish()
150+
f.debug_struct("BearerCredentialsConfig").field("token", &"[REDACTED]").finish()
160151
}
161152
}
162153

@@ -228,7 +219,7 @@ impl fmt::Debug for Credentials {
228219
match self {
229220
Credentials::ClientCredentials(config) => {
230221
f.debug_tuple("ClientCredentials").field(config).finish()
231-
}
222+
},
232223
Credentials::Bearer(config) => f.debug_tuple("Bearer").field(config).finish(),
233224
}
234225
}

src/auth/ed25519.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Ed25519 private key handling for JWT signing.
22
3-
use std::fmt;
4-
use std::path::Path;
3+
use std::{fmt, path::Path};
54

6-
use ed25519_dalek::{SigningKey, SECRET_KEY_LENGTH};
5+
use ed25519_dalek::{SECRET_KEY_LENGTH, SigningKey};
76
use zeroize::Zeroizing;
87

98
use crate::Error;
@@ -74,9 +73,7 @@ impl Ed25519PrivateKey {
7473
/// ```
7574
pub fn generate() -> Self {
7675
let mut csprng = rand::rngs::OsRng;
77-
Self {
78-
key: SigningKey::generate(&mut csprng),
79-
}
76+
Self { key: SigningKey::generate(&mut csprng) }
8077
}
8178

8279
/// Creates a key from raw bytes.
@@ -111,9 +108,7 @@ impl Ed25519PrivateKey {
111108
// Wrap in Zeroizing for secure cleanup
112109
let zeroizing_bytes = Zeroizing::new(key_bytes);
113110

114-
Ok(Self {
115-
key: SigningKey::from_bytes(&zeroizing_bytes),
116-
})
111+
Ok(Self { key: SigningKey::from_bytes(&zeroizing_bytes) })
117112
}
118113

119114
/// Creates a key from a hex-encoded string.

src/auth/provider.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Credentials provider trait for dynamic credential management.
22
3-
use std::future::Future;
4-
use std::pin::Pin;
5-
use std::sync::Arc;
3+
use std::{future::Future, pin::Pin, sync::Arc};
64

75
use crate::Error;
86

@@ -164,9 +162,7 @@ pub struct StaticTokenProvider {
164162
impl StaticTokenProvider {
165163
/// Creates a new static token provider.
166164
pub fn new(token: impl Into<String>) -> Self {
167-
Self {
168-
token: Arc::from(token.into()),
169-
}
165+
Self { token: Arc::from(token.into()) }
170166
}
171167
}
172168

@@ -226,17 +222,13 @@ mod tests {
226222

227223
impl CustomProvider {
228224
fn new() -> Self {
229-
Self {
230-
counter: std::sync::atomic::AtomicU32::new(0),
231-
}
225+
Self { counter: std::sync::atomic::AtomicU32::new(0) }
232226
}
233227
}
234228

235229
impl CredentialsProvider for CustomProvider {
236230
fn get_token(&self) -> CredentialsFuture<'_> {
237-
let count = self
238-
.counter
239-
.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
231+
let count = self.counter.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
240232
Box::pin(async move { Ok(format!("token_{}", count)) })
241233
}
242234

@@ -253,10 +245,7 @@ mod tests {
253245
async fn test_custom_provider() {
254246
let provider = CustomProvider::new();
255247
assert!(provider.supports_refresh());
256-
assert_eq!(
257-
provider.refresh_hint(),
258-
Some(std::time::Duration::from_secs(300))
259-
);
248+
assert_eq!(provider.refresh_hint(), Some(std::time::Duration::from_secs(300)));
260249

261250
let token1 = provider.get_token().await.unwrap();
262251
let token2 = provider.get_token().await.unwrap();
@@ -269,10 +258,7 @@ mod tests {
269258
let provider: Arc<dyn CredentialsProvider> = Arc::new(CustomProvider::new());
270259
// Test that Arc properly delegates all methods
271260
assert!(provider.supports_refresh());
272-
assert_eq!(
273-
provider.refresh_hint(),
274-
Some(std::time::Duration::from_secs(300))
275-
);
261+
assert_eq!(provider.refresh_hint(), Some(std::time::Duration::from_secs(300)));
276262
let token = provider.get_token().await.unwrap();
277263
assert_eq!(token, "token_0");
278264
}
@@ -282,10 +268,7 @@ mod tests {
282268
let provider: Box<dyn CredentialsProvider> = Box::new(CustomProvider::new());
283269
// Test that Box properly delegates all methods
284270
assert!(provider.supports_refresh());
285-
assert_eq!(
286-
provider.refresh_hint(),
287-
Some(std::time::Duration::from_secs(300))
288-
);
271+
assert_eq!(provider.refresh_hint(), Some(std::time::Duration::from_secs(300)));
289272
let token = provider.get_token().await.unwrap();
290273
assert_eq!(token, "token_0");
291274
}

0 commit comments

Comments
 (0)