Struct SshHost

Source
pub struct SshHost { /* private fields */ }
Expand description

this structure is used for storing the hostdata for easier storrage of the related information

The name field is the name of the remote.

The address field store the address of the remote hosts.

The port is for the remote port that ssh must use to connect.

The private_key is the path to the private_key to use.

Implementations§

Source§

impl SshHost

Source

pub fn new( name: String, address: String, user: Option<String>, port: Option<i64>, private_key: Option<PathBuf>, ) -> SshHost

return a new struct SshHost

§Examples
use std::path::PathBuf;

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), Some(String::from("user")), None, Some(PathBuf::from("private_key")));
assert_eq!(val.get_name(), String::from("hello"));
assert_eq!(val.get_address(), String::from("127.0.0.1"));
assert_eq!(val.get_user(), String::from("user"));
assert_eq!(val.get_port(), 22);
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key"));
assert_eq!(val.is_reachable(), true);
assert_eq!(val.get_url().unwrap(), String::from("127.0.0.1:22"));
Source

pub fn get_name(&self) -> String

return the name of the remote

§Examples

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_name(), String::from("hello"));
Source

pub fn set_name(&mut self, new_name: String)

set the name of the remote

§Examples

let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_name(), String::from("hello"));
val.set_name(String::from("foobar"));
assert_eq!(val.get_name(), String::from("foobar"));
Source

pub fn get_address(&self) -> String

return the address of the remote

§Examples

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_address(), String::from("127.0.0.1"));
Source

pub fn set_address(&mut self, new_address: String)

set the address of the remote

§Examples

let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.2"), None, None, None);
assert_eq!(val.get_address(), String::from("127.0.0.2"));
val.set_address(String::from("127.0.0.1"));
assert_eq!(val.get_address(), String::from("127.0.0.1"));
Source

pub fn get_user(&self) -> String

return the user of the remote

§Examples

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), Some(String::from("user")), None, None);
assert_eq!(val.get_user(), String::from("user"));
Source

pub fn set_user(&mut self, new_user: String)

set the address of the remote

§Examples

let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), Some(String::from("user")), None, None);
assert_eq!(val.get_user(), String::from("user"));
val.set_user(String::from("root"));
assert_eq!(val.get_user(), String::from("root"));
Source

pub fn get_port(&self) -> i64

return the port of the remote

§Examples

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, Some(2222), None);
assert_eq!(val.get_port(), 2222);
Source

pub fn set_port(&mut self, new_port: i64)

set the port of the remote

§Examples

let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_port(), 22);
val.set_port(2222);
assert_eq!(val.get_port(), 2222);
Source

pub fn get_private_key(&self) -> Option<PathBuf>

return the private key file of the remote

§Examples
use std::path::PathBuf;

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, Some(PathBuf::from("private_key")));
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key"));
Source

pub fn set_private_key(&mut self, new_key: Option<PathBuf>)

set the the private_key of the remote

§Examples
use std::path::PathBuf;

let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, Some(PathBuf::from("private_key")));
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key"));
val.set_private_key(Some(PathBuf::from("private_key_2")));
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key_2"));
Source

pub fn is_reachable(&self) -> bool

return if the remote hosts is available or not

§Examples
use std::path::PathBuf;

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.is_reachable(), true);
Source

pub fn set_reachable(&mut self, new_val: bool)

set the remote value

§Examples
use std::path::PathBuf;

let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.is_reachable(), true);
val.set_reachable(false);
assert_eq!(val.is_reachable(), false);
Source

pub fn get_url(&self) -> Result<String, &str>

return the url of the hosts

It will be in the form of address:port like 127.0.0.1:22

§Examples
use std::path::PathBuf;

let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, Some(2222), None);
assert_eq!(val.get_url().unwrap(), String::from("127.0.0.1:2222"));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.