Skip to main content

connect_lazy

Function connect_lazy 

Source
pub fn connect_lazy(ep: &ApiEndpoint) -> Result<Channel, FinamError>
Expand description

Builds a lazily connecting channel to ep.

Nothing is sent here. Connection errors surface on the first call, and tonic reconnects on its own after a drop. TLS (webpki roots) is switched on when the URL starts with https://.

§Errors

FinamError::Config when the URL is not a valid endpoint or the TLS settings are refused.

§Examples

use brokapi_finam_protocol::client::connect_lazy;
use brokapi_finam_protocol::{ApiEndpoint, FinamError};

// A valid address gives a channel without touching the network.
assert!(connect_lazy(&ApiEndpoint::new("http://127.0.0.1:1")).is_ok());
// Garbage is a configuration error.
let err = connect_lazy(&ApiEndpoint::new("not a url")).unwrap_err();
assert!(matches!(err, FinamError::Config(_)));