streamnative / pulsar-rs

Rust Client library for Apache Pulsar
Other
369 stars 121 forks source link

Concretize types for client building #284

Open glaziermag opened 1 year ago

glaziermag commented 1 year ago

The Pulsar consumer builder is generic over DeserializeMessage but the async Pulsar client building seems to require concrete types.

let client = pulsar::Pulsar::builder("pulsar://localhost:6650", TokioExecutor)
    .build()
    .await
    .expect("Failed to create Pulsar client");

# type TestData = String;
let mut consumer: Consumer<TestData, _> = client
     .consumer()
     .with_topic("non-persistent://public/default/test")
     .with_consumer_name("test_consumer")
     .with_subscription("test_subscription")
     .build() // works with string type
     .await?;

# type TestData = unknown;  // toy generic example
  let mut consumer: Consumer<{unknown}, _> = client
     .consumer()
     .with_topic("non-persistent://public/default/test")
     .with_consumer_name("test_consumer")
     .with_subscription("test_subscription")
     .build()     // type inside `async` block must be known in this context
                       // cannot infer type for type parameter `T` declared on the method `build`
     .await?;

Should the client builder build() accept trait objects?