pub struct Address {
pub host: Option<String>,
pub port: Option<u16>,
pub path: Option<String>,
}
Expand description
A simple struct to represent a server address, with host:port or socket path.
Fields§
§host: Option<String>
Host or ip address of the server.
port: Option<u16>
Port to connect to the server.
path: Option<String>
Use unix socket path to connect.
Implementations§
source§impl Address
impl Address
sourcepub fn new(host: impl Into<String>, port: u16) -> Self
pub fn new(host: impl Into<String>, port: u16) -> Self
Construct server address with host and port.
Examples found in repository?
examples/demo.rs (line 17)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() -> Result<(), mdsn::DsnError> {
// The two styles are equivalent.
let _ = Dsn::from_str("taos://root:taosdata@host1:6030,host2:6030/db")?;
let dsn: Dsn = "taos://root:taosdata@host1:6030,host2:6030/db".parse()?;
assert_eq!(dsn.driver, "taos");
assert_eq!(dsn.username.unwrap(), "root");
assert_eq!(dsn.password.unwrap(), "taosdata");
assert_eq!(dsn.subject.unwrap(), "db");
assert_eq!(dsn.addresses.len(), 2);
assert_eq!(
dsn.addresses,
vec![
mdsn::Address::new("host1", 6030),
mdsn::Address::new("host2", 6030),
]
);
Ok(())
}
sourcepub fn from_host(host: impl Into<String>) -> Self
pub fn from_host(host: impl Into<String>) -> Self
Construct server address with host or ip address only.
sourcepub fn from_path(path: impl Into<String>) -> Self
pub fn from_path(path: impl Into<String>) -> Self
Construct server address with unix socket path.
pub fn is_empty(&self) -> bool
Trait Implementations§
source§impl PartialEq for Address
impl PartialEq for Address
impl Eq for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnwindSafe for Address
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more