Skip to main content

SplitCombiner

Struct SplitCombiner 

Source
pub struct SplitCombiner<S: CommunicationService, R: CommunicationService> { /* private fields */ }
Expand description

将事件接收与API发送分为两个不同服务实现
服务分为 send_sideread_side
其中,send_side 负责API发送服务,read_side 负责事件接收服务
send_side 的事件通道由一个 processor task 负责
processor 将 send_side 的API响应事件并入原事件通道,其余事件丢弃

§Examples

use std::time::Duration;
use onebot_api::communication::http::HttpService;
use onebot_api::communication::sse::SseService;
use onebot_api::communication::combiner::SplitCombiner;
use onebot_api::communication::utils::Client;

let http_service = HttpService::new("https://example.com", Some("example_token".to_string())).unwrap();
let sse_service = SseService::new("https://example.com/_events", Some("example_token".to_string())).unwrap();
let combiner = SplitCombiner::new(http_service, sse_service);
let client = Client::new_with_options(combiner, Duration::from_secs(5), None, None);
client.start_service().await.unwrap();

Implementations§

Source§

impl<S: CommunicationService, R: CommunicationService> SplitCombiner<S, R>

Source

pub fn new(send_side: S, read_side: R) -> Self

Trait Implementations§

Source§

impl<S: CommunicationService, R: CommunicationService> CommunicationService for SplitCombiner<S, R>

Source§

fn install( &mut self, api_receiver: InternalAPIReceiver, event_sender: InternalEventSender, )

安装服务
该方法仅进行服务的依赖注入,并不真正创建任务
应具备幂等性
Source§

fn uninstall(&mut self)

卸载服务
服务应回收安装后产生的一切副作用和安装时注入的依赖
应具备幂等性
Source§

fn stop(&self)

停止服务
不同于 uninstall 方法 ,stop 方法仅需要回收安装后产生的副作用,并不需要回收安装时注入的依赖
应具备幂等性
Source§

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ServiceStartResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

开始服务
服务内应保证任务在服务的生命周期内最多存在一个
由于在服务生命周期内最多存在一个任务,所以该方法 应具备幂等性
Source§

fn restart<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ServiceStartResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

重启服务
不具备幂等性
Source§

impl<S: CommunicationService, R: CommunicationService> Drop for SplitCombiner<S, R>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S, R> Freeze for SplitCombiner<S, R>
where S: Freeze, R: Freeze,

§

impl<S, R> !RefUnwindSafe for SplitCombiner<S, R>

§

impl<S, R> Send for SplitCombiner<S, R>

§

impl<S, R> Sync for SplitCombiner<S, R>

§

impl<S, R> Unpin for SplitCombiner<S, R>
where S: Unpin, R: Unpin,

§

impl<S, R> UnsafeUnpin for SplitCombiner<S, R>
where S: UnsafeUnpin, R: UnsafeUnpin,

§

impl<S, R> !UnwindSafe for SplitCombiner<S, R>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoService for T
where T: CommunicationService + 'static,

Source§

fn into(self) -> impl CommunicationService + 'static

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more