Skip to content

Commit f6d3d9d

Browse files
committed
Apply cargo fmt and set up CI
1 parent 427bd71 commit f6d3d9d

19 files changed

Lines changed: 544 additions & 380 deletions

examples/authentication.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cups_rs::{
2-
auth::{set_password_callback, get_password, do_authentication},
3-
get_destination, create_job, Result,
2+
Result,
3+
auth::{do_authentication, get_password, set_password_callback},
4+
create_job, get_destination,
45
};
56
use std::io::{self, Write};
67

@@ -14,14 +15,14 @@ fn main() -> Result<()> {
1415
println!("Prompt: {}", prompt);
1516
println!("Method: {}", method);
1617
println!("Resource: {}", resource);
17-
18+
1819
print!("Enter password (or 'q' to quit): ");
1920
io::stdout().flush().unwrap();
20-
21+
2122
let mut input = String::new();
2223
io::stdin().read_line(&mut input).unwrap();
2324
let input = input.trim();
24-
25+
2526
if input == "q" || input.is_empty() {
2627
println!("Authentication cancelled");
2728
None
@@ -38,16 +39,14 @@ fn main() -> Result<()> {
3839
}
3940

4041
// Try to access a printer that might require authentication
41-
let printer_name = std::env::args()
42-
.nth(1)
43-
.unwrap_or_else(|| "PDF".to_string());
42+
let printer_name = std::env::args().nth(1).unwrap_or_else(|| "PDF".to_string());
4443

4544
println!("\nTrying to access printer: {}", printer_name);
46-
45+
4746
match get_destination(&printer_name) {
4847
Ok(destination) => {
4948
println!("Successfully connected to: {}", destination.full_name());
50-
49+
5150
// Try to create a job (this might trigger authentication)
5251
println!("Attempting to create a job...");
5352
match create_job(&destination, "Authentication test job") {
@@ -56,7 +55,7 @@ fn main() -> Result<()> {
5655
}
5756
Err(e) => {
5857
println!("Job creation failed: {}", e);
59-
58+
6059
// Try manual authentication
6160
println!("Attempting manual authentication...");
6261
match do_authentication(None, "POST", "/") {
@@ -74,12 +73,12 @@ fn main() -> Result<()> {
7473
// Test removing the callback
7574
println!("\nRemoving password callback...");
7675
set_password_callback(None)?;
77-
76+
7877
match get_password("Test prompt after removal:", None, "GET", "/test") {
7978
Some(password) => println!("Unexpected password: {}", password),
8079
None => println!("Callback correctly removed - no password provided"),
8180
}
8281

8382
println!("\nAuthentication example completed!");
8483
Ok(())
85-
}
84+
}

examples/discover_printers.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cups_rs::{
2-
get_all_destinations, get_default_destination, find_destinations,
3-
Destinations, PRINTER_LOCAL, PRINTER_REMOTE, Result,
2+
Destinations, PRINTER_LOCAL, PRINTER_REMOTE, Result, find_destinations, get_all_destinations,
3+
get_default_destination,
44
};
55

66
fn main() -> Result<()> {
@@ -44,7 +44,10 @@ fn main() -> Result<()> {
4444
// Method 2: Advanced management (new API)
4545
println!("\n--- Advanced Destination Management ---");
4646
let mut managed_destinations = Destinations::get_all()?;
47-
println!("Managing {} destinations with new API", managed_destinations.len());
47+
println!(
48+
"Managing {} destinations with new API",
49+
managed_destinations.len()
50+
);
4851

4952
// Add a test destination to demonstrate management
5053
println!("Adding test destination 'MyTestPrinter'...");
@@ -58,13 +61,17 @@ fn main() -> Result<()> {
5861
// Set a new default if we have printers
5962
if let Some(first_dest) = destinations.first() {
6063
println!("Setting '{}' as default...", first_dest.name);
61-
managed_destinations.set_default_destination(&first_dest.name, first_dest.instance.as_deref())?;
64+
managed_destinations
65+
.set_default_destination(&first_dest.name, first_dest.instance.as_deref())?;
6266
println!(" ✓ Default updated");
6367
}
6468

6569
// Clean up test destination
6670
let removed = managed_destinations.remove_destination("MyTestPrinter", None)?;
67-
println!("Test destination removed: {}", if removed { "✓" } else { "✗" });
71+
println!(
72+
"Test destination removed: {}",
73+
if removed { "✓" } else { "✗" }
74+
);
6875

6976
// Show current default (existing API)
7077
match get_default_destination() {

examples/multi_document.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
use cups_rs::{
2-
create_job, get_destination, get_job_info, Result, FORMAT_TEXT,
3-
};
1+
use cups_rs::{FORMAT_TEXT, Result, create_job, get_destination, get_job_info};
42

53
fn main() -> Result<()> {
64
println!("CUPS Multi-Document Job Example");
75

8-
let printer_name = std::env::args()
9-
.nth(1)
10-
.unwrap_or_else(|| "PDF".to_string());
6+
let printer_name = std::env::args().nth(1).unwrap_or_else(|| "PDF".to_string());
117

128
let destination = get_destination(&printer_name)?;
139
println!("Using printer: {}", destination.full_name());
1410

1511
let job = create_job(&destination, "Multi-document job")?;
1612
println!("Created job ID: {}", job.id);
1713

18-
std::fs::write("doc1.txt", "Document 1: First page of the multi-document job\n")?;
19-
std::fs::write("doc2.txt", "Document 2: Second page of the multi-document job\n")?;
20-
std::fs::write("doc3.txt", "Document 3: Final page of the multi-document job\n")?;
14+
std::fs::write(
15+
"doc1.txt",
16+
"Document 1: First page of the multi-document job\n",
17+
)?;
18+
std::fs::write(
19+
"doc2.txt",
20+
"Document 2: Second page of the multi-document job\n",
21+
)?;
22+
std::fs::write(
23+
"doc3.txt",
24+
"Document 3: Final page of the multi-document job\n",
25+
)?;
2126

2227
println!("Submitting document 1 (not last)...");
2328
job.submit_file_with_options("doc1.txt", FORMAT_TEXT, &[], false)?;
2429

2530
println!("Submitting document 2 (not last)...");
26-
let doc2_options = vec![
27-
("print-quality".to_string(), "high".to_string()),
28-
];
31+
let doc2_options = vec![("print-quality".to_string(), "high".to_string())];
2932
job.submit_file_with_options("doc2.txt", FORMAT_TEXT, &doc2_options, false)?;
3033

3134
println!("Submitting document 3 (last document)...");
@@ -47,4 +50,4 @@ fn main() -> Result<()> {
4750

4851
println!("Multi-document job completed! Check: lpstat -o");
4952
Ok(())
50-
}
53+
}

examples/server_config.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use cups_rs::{
2+
Result,
23
config::{
3-
get_server, set_server, get_user, set_user, get_encryption, set_encryption,
4-
get_user_agent, set_user_agent, CupsConfig, EncryptionMode,
4+
CupsConfig, EncryptionMode, get_encryption, get_server, get_user, get_user_agent,
5+
set_encryption, set_server, set_user, set_user_agent,
56
},
6-
get_all_destinations, Result,
7+
get_all_destinations,
78
};
89

910
fn main() -> Result<()> {
@@ -17,7 +18,7 @@ fn main() -> Result<()> {
1718

1819
// Test individual configuration functions
1920
println!("\n--- Testing Individual Configuration ---");
20-
21+
2122
// Test server configuration
2223
println!("Setting server to 'print.example.com:8631'...");
2324
set_server(Some("print.example.com:8631"))?;
@@ -44,7 +45,7 @@ fn main() -> Result<()> {
4445
set_user(None)?;
4546
set_encryption(EncryptionMode::IfRequested);
4647
set_user_agent(None)?;
47-
48+
4849
println!("Server restored to: {}", get_server());
4950
println!("User restored to: {}", get_user());
5051
println!("Encryption restored to: {:?}", get_encryption());
@@ -69,7 +70,10 @@ fn main() -> Result<()> {
6970
// Note: This will likely fail since scoped.example.com doesn't exist
7071
match get_all_destinations() {
7172
Ok(destinations) => {
72-
println!(" Successfully connected! Found {} printers", destinations.len());
73+
println!(
74+
" Successfully connected! Found {} printers",
75+
destinations.len()
76+
);
7377
}
7478
Err(e) => {
7579
println!(" Expected connection failure: {}", e);
@@ -95,13 +99,13 @@ fn main() -> Result<()> {
9599
.with_user("developer")?
96100
.with_encryption(EncryptionMode::Never)
97101
.with_user_agent("DevApp/1.0-debug")?;
98-
102+
99103
let dev_summary = _dev_config.current_config();
100104
println!(" {}", dev_summary);
101105

102106
// The configuration will be automatically restored when _dev_config is dropped
103107
println!("\nServer configuration demo completed!");
104108
println!("Note: All configurations are thread-local in CUPS");
105-
109+
106110
Ok(())
107-
}
111+
}

0 commit comments

Comments
 (0)