pub struct BotFarm<S> { /* private fields */ }farm only.Implementations§
Source§impl<C: ClientApi, P: EventParser> BotFarm<Init<C, P>>
impl<C: ClientApi, P: EventParser> BotFarm<Init<C, P>>
Sourcepub async fn init(
farm_name: String,
client: C,
events: EventStream<P>,
) -> Result<Self, C::Error>
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.
Sourcepub fn users_count(&self) -> usize
pub fn users_count(&self) -> usize
Total users count on the farm excluding the farm user
Sourcepub fn users(&self) -> impl Iterator<Item = &User>
pub fn users(&self) -> impl Iterator<Item = &User>
Iterate over all users excluding the farm user
pub fn user(&self, name: &str) -> Option<&User>
pub async fn remove(&mut self, user_id: UserId) -> Result<(), C::Error>
pub async fn remove_by_name(&mut self, name: &str) -> Result<(), C::Error>
Sourcepub async fn prepare_bot(
&mut self,
settings: BotSettings,
) -> Result<UserId, CreateError<C::Error>>where
C: Clone,
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.
Sourcepub async fn prepare_ghost(
&mut self,
settings: BotSettings,
) -> Result<UserId, CreateError<C::Error>>where
C: Clone,
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.
Sourcepub fn run(self) -> (BotFarm<Running<C, P>>, EventStream<P>)
pub fn run(self) -> (BotFarm<Running<C, P>>, EventStream<P>)
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
Userstruct)
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>>
impl<C: 'static + ClientApi, P: EventParser> BotFarm<Running<C, P>>
Sourcepub fn ghost(&self, user_id: UserId) -> Option<FarmBot<C>>
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.
Sourcepub fn take_bot(&self, user_id: UserId) -> (FarmBot<C>, EventStream<P>)
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.
Sourcepub fn take_bot_checked(
&self,
user_id: UserId,
) -> Option<(FarmBot<C>, EventStream<P>)>
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.
Sourcepub async fn create_bot(
&self,
settings: BotSettings,
) -> Result<(FarmBot<C>, EventStream<P>), CreateError<C::Error>>
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.
Sourcepub async fn get_or_create_bot(
&self,
settings: BotSettings,
) -> Result<(FarmBot<C>, EventStream<P>), CreateError<C::Error>>
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
Sourcepub async fn create_ghost(
&self,
settings: BotSettings,
) -> Result<FarmBot<C>, CreateError<C::Error>>
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.
Sourcepub async fn get_or_create_ghost(
&self,
settings: BotSettings,
) -> Result<FarmBot<C>, CreateError<C::Error>>
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.
Trait Implementations§
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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