Skip to content

Commit dce1218

Browse files
committed
refactor: update examples to return LightstreamerError
- Add From<VarError> impl to LightstreamerError for env::var support - Update all 7 example binaries to return LightstreamerError instead of Box<dyn Error>
1 parent d5a56c5 commit dce1218

8 files changed

Lines changed: 14 additions & 8 deletions

File tree

examples/simple/src/bin/channel_example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const MAX_CONNECTION_ATTEMPTS: u64 = 1;
1515
/// item updates through a tokio channel, enabling asynchronous processing
1616
/// in a separate task.
1717
#[tokio::main]
18-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
18+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
1919
setup_logger();
2020

2121
info!("🚀 Starting Channel-based Subscription Example");

examples/simple/src/bin/connection_manager_example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl SubscriptionListener for ConnectionAwareListener {
7272
}
7373

7474
#[tokio::main]
75-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
75+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
7676
setup_logger();
7777

7878
info!("🚀 Starting ConnectionManager Example");
@@ -223,7 +223,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
223223
fn create_stock_subscription(
224224
name: &str,
225225
items: Vec<&str>,
226-
) -> Result<Subscription, Box<dyn std::error::Error>>
226+
) -> Result<Subscription, lightstreamer_rs::utils::LightstreamerError>
227227
where
228228
Subscription: Sized,
229229
{

examples/simple/src/bin/easy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use lightstreamer_rs::utils::setup_logger;
1515
use tracing::info;
1616

1717
#[tokio::main]
18-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
18+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
1919
setup_logger();
2020

2121
info!("🚀 Starting Easy Lightstreamer Example");

examples/simple/src/bin/ig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Config {
2525
}
2626

2727
#[tokio::main]
28-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
28+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
2929
setup_logger();
3030
//
3131
// Create a new subscription instance.

examples/simple/src/bin/ig_advanced.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl SubscriptionListener for AdvancedFinancialListener {
4444
}
4545

4646
#[tokio::main]
47-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
47+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
4848
setup_logger();
4949
info!("🚀 Starting IG Markets Advanced Lightstreamer Client with ConnectionManager");
5050

examples/simple/src/bin/minimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use lightstreamer_rs::client::{ClientConfig, SimpleClient, SubscriptionParams};
1010
use lightstreamer_rs::subscription::SubscriptionMode;
1111

1212
#[tokio::main]
13-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
13+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
1414
// 1. Configure
1515
let config =
1616
ClientConfig::new("http://push.lightstreamer.com/lightstreamer").adapter_set("DEMO");

examples/simple/src/bin/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl SubscriptionListener for MySubscriptionListener {
3838
}
3939

4040
#[tokio::main]
41-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
41+
async fn main() -> Result<(), lightstreamer_rs::utils::LightstreamerError> {
4242
setup_logger();
4343
//
4444
// Create a new subscription instance.

src/utils/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ impl From<crate::connection::ReconnectionError> for LightstreamerError {
199199
}
200200
}
201201

202+
impl From<std::env::VarError> for LightstreamerError {
203+
fn from(e: std::env::VarError) -> Self {
204+
LightstreamerError::Configuration(e.to_string())
205+
}
206+
}
207+
202208
/// Legacy exception type for backward compatibility.
203209
/// Prefer using `LightstreamerError::InvalidArgument` directly.
204210
#[deprecated(

0 commit comments

Comments
 (0)