Skip to main content

BotFarm

Struct BotFarm 

Source
pub struct BotFarm<S> { /* private fields */ }
Available on crate feature farm only.

Implementations§

Source§

impl<C: ClientApi, P: EventParser> BotFarm<Init<C, P>>

Source

pub async fn init( farm_name: String, client: C, events: EventStream<P>, ) -> Result<Self, C::Error>

The farm_name is the name of the special bot managing the bot farm, it cannot be accessed directly. It is mostly used as an intermediary user deleting other users under the hood.

Source

pub fn users_count(&self) -> usize

Total users count on the farm excluding the farm user

Source

pub fn users(&self) -> impl Iterator<Item = &User>

Iterate over all users excluding the farm user

Source

pub fn user(&self, name: &str) -> Option<&User>

Source

pub async fn remove(&mut self, user_id: UserId) -> Result<(), C::Error>

Source

pub async fn remove_by_name(&mut self, name: &str) -> Result<(), C::Error>

Source

pub async fn prepare_bot( &mut self, settings: BotSettings, ) -> Result<UserId, CreateError<C::Error>>
where C: Clone,

Prepare a user with its own event stream. Use take_bot to extract the bot then.

Source

pub async fn prepare_ghost( &mut self, settings: BotSettings, ) -> Result<UserId, CreateError<C::Error>>
where C: Clone,

Prepare a ghost user. Ghosts don’t have their own event streams, all their events end up in the general bot farm stream.

Source

pub fn run(self) -> (BotFarm<Running<C, P>>, EventStream<P>)
where C: 'static + Send, C::Error: Send, P: 'static + Send,

Transition the farm to the running state by starting dispatching and routing events.

Returns a running farm and a general EventStream that receives:

  • events belonging to ghost users
  • general events not addressed to a specific user(events without User struct)

Farm user events are filtered out

Handle events or discard the returned event stream to avoid memory leaks.

Source§

impl<C: 'static + ClientApi, P: EventParser> BotFarm<Running<C, P>>
where C::Error: Send,

Source

pub fn ghost(&self, user_id: UserId) -> Option<FarmBot<C>>

Return a ghost handle for user_id, or None if the user does not exist or is a bot.

Each call produces a new independent FarmBot handle. Multiple handles for the same ghost share the underlying command channel and with the xftp feature enabled the same download table, so concurrent download_file calls on different handles will work correctly.

Source

pub fn take_bot(&self, user_id: UserId) -> (FarmBot<C>, EventStream<P>)

Take the bot handle and its EventStream out of the farm.

This is a one-shot operation: the internal event receiver is consumed and cannot be taken again. Panics if user_id is unknown, was registered as a ghost, or was already taken. Use take_bot_checked to avoid the panic.

Source

pub fn take_bot_checked( &self, user_id: UserId, ) -> Option<(FarmBot<C>, EventStream<P>)>

Non-panicking variant of take_bot. Returns None if the user is unknown, is a ghost, or was already taken.

Source

pub async fn create_bot( &self, settings: BotSettings, ) -> Result<(FarmBot<C>, EventStream<P>), CreateError<C::Error>>

Create a new SimpleX user, as a bot, and return its handle and event stream.

Unlike prepare_bot, this is available at runtime after run. In order to route events correctly all event streams are paused and don’t receive any events during the bot creation process.

Source

pub async fn get_or_create_bot( &self, settings: BotSettings, ) -> Result<(FarmBot<C>, EventStream<P>), CreateError<C::Error>>

Return the existing bot if a user with the given display name is already known, otherwise create one via create_bot.

§Eventual consistency

This method is eventually consistent and may return CreateError::Desync if the same bot is getting created/deleted from multiple threads. You’re supposed to retry this call to get the actual result on CreateError::Desync

Source

pub async fn create_ghost( &self, settings: BotSettings, ) -> Result<FarmBot<C>, CreateError<C::Error>>

Create a new SimpleX user, register it as a ghost, and return a handle to it.

The ghost’s events are routed to the general EventStream returned when running a farm.

Source

pub async fn get_or_create_ghost( &self, settings: BotSettings, ) -> Result<FarmBot<C>, CreateError<C::Error>>

Return a ghost handle for the named user if it already exists, otherwise create one via create_ghost.

Same eventual consistency caveats as get_or_create_bot.

Source

pub async fn delete(&self, user_id: UserId) -> Result<(), C::Error>

Permanently delete a user and remove it from the routing table.

Any FarmBot handles that were already taken for this user remain alive but all subsequent commands on them will fail with an API error.

Trait Implementations§

Source§

impl<S: Clone> Clone for BotFarm<S>

Source§

fn clone(&self) -> BotFarm<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> Freeze for BotFarm<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for BotFarm<S>
where S: RefUnwindSafe,

§

impl<S> Send for BotFarm<S>
where S: Send,

§

impl<S> Sync for BotFarm<S>
where S: Sync,

§

impl<S> Unpin for BotFarm<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for BotFarm<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for BotFarm<S>
where S: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V