1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#[cfg(feature = "sql-browser-tokio")]
mod tokio;
#[cfg(feature = "sql-browser-async-std")]
mod async_std;
use crate::client::Config;
use async_trait::async_trait;
#[async_trait]
pub trait SqlBrowser {
async fn connect_named(builder: &Config) -> crate::Result<Self>
where
Self: Sized + Send + Sync;
}
#[cfg(any(feature = "sql-browser-async-std", feature = "sql-browser-tokio"))]
fn get_port_from_sql_browser_reply(
mut buf: Vec<u8>,
len: usize,
instance_name: &str,
) -> crate::Result<u16> {
buf.truncate(len);
let err = crate::Error::Conversion(
format!("Could not resolve SQL browser instance {}", instance_name).into(),
);
if len == 0 {
return Err(err);
}
let response = std::str::from_utf8(&buf[3..len])?;
let port: u16 = response
.find("tcp;")
.and_then(|pos| response[pos..].split(';').nth(1))
.ok_or(err)
.and_then(|val| Ok(val.parse()?))?;
Ok(port)
}