Struct CtfLoopResponder

Source
pub struct CtfLoopResponder<'a> { /* private fields */ }
Expand description

CtfLoopResponder is a Builder pattern like to build a loop responder.

The main function connect to the server and run the same routine on every incoming message.

Implementations§

Source§

impl<'a> CtfLoopResponder<'a>

Source

pub fn new() -> Self

Build a new empty CtfLoopResponder

Source

pub fn localhost(port: u16) -> Self

Build a CtfLoopResponder for localhost on given port.

Source

pub fn url(self, url: &'a str) -> Self

Set url

Source

pub fn port(self, port: u16) -> Self

Set port

Source

pub fn timeout(self, timeout: u64) -> Self

Set timeout

Source

pub fn responder_func( self, responder_func: impl Fn(&str) -> Option<String> + 'static, ) -> Self

Set the responder routine runned on each server’s message.

Source

pub fn connect_and_work(&self) -> Result<String, CtfTcpHandlerError>

Connect to the server and use the struct routine to answer each incoming message.

§Errors

The function will fail if either url, port or responder routine is not defined. It may also fails if TCP connection fail.

Trait Implementations§

Source§

impl<'a> Default for CtfLoopResponder<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CtfLoopResponder<'a>

§

impl<'a> !RefUnwindSafe for CtfLoopResponder<'a>

§

impl<'a> !Send for CtfLoopResponder<'a>

§

impl<'a> !Sync for CtfLoopResponder<'a>

§

impl<'a> Unpin for CtfLoopResponder<'a>

§

impl<'a> !UnwindSafe for CtfLoopResponder<'a>

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.