pub struct Mta {
pub ip: String,
pub port: u16,
pub auth: Auth,
pub http: bool,
}
Expand description
A struct representing the configuration for making requests to the MTA service.
Fields§
§ip: String
The IP address of the MTA server.
port: u16
The port number of the MTA server.
auth: Auth
The authentication credentials for accessing the MTA server.
http: bool
Determines whether HTTP or HTTPS should be used for requests.
Implementations§
Source§impl Mta
impl Mta
Sourcepub fn new(ip: String, port: u16, auth: Auth, http: bool) -> Mta
pub fn new(ip: String, port: u16, auth: Auth, http: bool) -> Mta
Creates a new Mta
instance.
§Arguments
ip
- The IP address of the MTA server.port
- The port number of the MTA server.auth
- Authentication credentials for accessing the MTA server.http
- Whether to use HTTP (true
) or HTTPS (false
) for requests.
§Example
use mta_sdk::client;
let auth = client::Auth {
username: "user".to_string(),
password: "pass".to_string(),
};
let mta = client::Mta::new("127.0.0.1".to_string(), 22005, auth, true);
Sourcepub async fn call(
&self,
resource: &str,
function: &str,
args: Vec<String>,
) -> Result<String, Errors>
pub async fn call( &self, resource: &str, function: &str, args: Vec<String>, ) -> Result<String, Errors>
Makes a remote call to the MTA service.
This method sends a POST request to the specified resource and function on the MTA server, passing the provided arguments.
§Arguments
resource
- The resource to call.function
- The function to invoke.args
- The arguments for the function call.
§Returns
Returns a Result
containing the response text if the request is successful,
or an Errors
enum if an error occurs during the request.
§Errors
Returns an HTTP404ERROR
variant of the Errors
enum if there is a request error.
§Example
use mta_sdk::client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let auth = client::Auth {
username: "user".to_string(),
password: "pass".to_string(),
};
let mta_instance = client::Mta::new("127.0.0.1".to_string(), 22005, auth, true);
let response = mta_instance.call("resource", "function", vec!["arg1".to_string()]).await?;
println!("Response: {}", response);
Ok(())
}
Sourcepub fn get_uri(&self) -> String
pub fn get_uri(&self) -> String
Returns the URI based on the configured HTTP/HTTPS setting.
§Example
use mta_sdk::client;
let auth = client::Auth {
username: "user".to_string(),
password: "pass".to_string(),
};
let instance = client::Mta::new("127.0.0.1".to_string(), 22005, auth, true);
let uri = instance.get_uri();
println!("URI: {}", uri);
Auto Trait Implementations§
impl Freeze for Mta
impl RefUnwindSafe for Mta
impl Send for Mta
impl Sync for Mta
impl Unpin for Mta
impl UnwindSafe for Mta
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