traq_bot_http

Struct Handler

Source
pub struct Handler<Service> { /* private fields */ }
Available on crate feature tower only.
Expand description

イベントハンドラです。

§Example

use std::convert::Infallible;

use tower::service_fn;
use traq_bot_http::{payloads, RequestParser};

async fn on_ping((state, payload): (i32, payloads::PingPayload)) -> Result<(), Infallible> {
    println!("state: {state:?}, ping: {payload:?}");
    // assert_eq!(state, 0);
    Ok(())
}

let parser = RequestParser::new("verification_token");
let handler = parser
    .into_handler()
    .on_ping(service_fn(on_ping))
    .with_state(0i32);

§Composing Handler

Handler はメソッドチェーンにより構成されます。使用可能なメソッドは以下の通りです。

適切に構成された HandlerService trait を実装します。各メソッドのドキュメントを参照してください。

Handler の構成時にはコンパイルエラーが出ない可能性がありますService trait を使用するライブラリ (axum 等) の条件も確認してください。

§Note

この構造体の型パラメータは unstable です。Handler<T>におけるTは予告なく変化する可能性があります。

Implementations§

Source§

impl<Service> Handler<Service>

Source

pub fn with_state<State>( self, state: State, ) -> Handler<WithState<State, Service>>

イベントハンドラにStateを追加します。Stateは以下の条件を満たす必要があります。

  • Cloneを実装している
§Example
use std::convert::Infallible;

use tower::service_fn;
use traq_bot_http::{payloads, RequestParser};

async fn on_ping(state: i32, payload: payloads::PingPayload) -> Result<(), Infallible> {
    println!("state: {state}, payload: {payload:?}");
    Ok(())
}

let parser = RequestParser::new("verification_token");
let handler = parser
    .into_handler()
    // これはinvalidです; with_stateはstateを使用するハンドラより後に置く必要があります
    // .with_state(0)
    .on_ping(service_fn(|(state, payload)| on_ping(state, payload)))
    .with_state(0);
Source§

impl<Service1> Handler<Service1>

Source

pub fn on_ping<Service2, Req>( self, service: Service2, ) -> Handler<OnPing<Service2, Service1, Req>>
where Service2: Service<Req>,

PingPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_joined<Service2, Req>( self, service: Service2, ) -> Handler<OnJoined<Service2, Service1, Req>>
where Service2: Service<Req>,

JoinedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_left<Service2, Req>( self, service: Service2, ) -> Handler<OnLeft<Service2, Service1, Req>>
where Service2: Service<Req>,

LeftPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_message_created<Service2, Req>( self, service: Service2, ) -> Handler<OnMessageCreated<Service2, Service1, Req>>
where Service2: Service<Req>,

MessageCreatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_message_deleted<Service2, Req>( self, service: Service2, ) -> Handler<OnMessageDeleted<Service2, Service1, Req>>
where Service2: Service<Req>,

MessageDeletedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_message_updated<Service2, Req>( self, service: Service2, ) -> Handler<OnMessageUpdated<Service2, Service1, Req>>
where Service2: Service<Req>,

MessageUpdatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_direct_message_created<Service2, Req>( self, service: Service2, ) -> Handler<OnDirectMessageCreated<Service2, Service1, Req>>
where Service2: Service<Req>,

DirectMessageCreatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_direct_message_deleted<Service2, Req>( self, service: Service2, ) -> Handler<OnDirectMessageDeleted<Service2, Service1, Req>>
where Service2: Service<Req>,

DirectMessageDeletedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_direct_message_updated<Service2, Req>( self, service: Service2, ) -> Handler<OnDirectMessageUpdated<Service2, Service1, Req>>
where Service2: Service<Req>,

DirectMessageUpdatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_bot_message_stamps_updated<Service2, Req>( self, service: Service2, ) -> Handler<OnBotMessageStampsUpdated<Service2, Service1, Req>>
where Service2: Service<Req>,

BotMessageStampsUpdatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_channel_created<Service2, Req>( self, service: Service2, ) -> Handler<OnChannelCreated<Service2, Service1, Req>>
where Service2: Service<Req>,

ChannelCreatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_channel_topic_changed<Service2, Req>( self, service: Service2, ) -> Handler<OnChannelTopicChanged<Service2, Service1, Req>>
where Service2: Service<Req>,

ChannelTopicChangedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_created<Service2, Req>( self, service: Service2, ) -> Handler<OnUserCreated<Service2, Service1, Req>>
where Service2: Service<Req>,

UserCreatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_stamp_created<Service2, Req>( self, service: Service2, ) -> Handler<OnStampCreated<Service2, Service1, Req>>
where Service2: Service<Req>,

StampCreatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_tag_added<Service2, Req>( self, service: Service2, ) -> Handler<OnTagAdded<Service2, Service1, Req>>
where Service2: Service<Req>,

TagAddedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_tag_removed<Service2, Req>( self, service: Service2, ) -> Handler<OnTagRemoved<Service2, Service1, Req>>
where Service2: Service<Req>,

TagRemovedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_created<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupCreated<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupCreatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_updated<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupUpdated<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupUpdatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_deleted<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupDeleted<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupDeletedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_member_added<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupMemberAdded<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupMemberAddedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_member_updated<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupMemberUpdated<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupMemberUpdatedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_member_removed<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupMemberRemoved<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupMemberRemovedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_admin_added<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupAdminAdded<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupAdminAddedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している
Source

pub fn on_user_group_admin_removed<Service2, Req>( self, service: Service2, ) -> Handler<OnUserGroupAdminRemoved<Service2, Service1, Req>>
where Service2: Service<Req>,

UserGroupAdminRemovedPayloadをhandleするServiceを登録します。

引数の型Service2Service<Req> traitを実装し、さらに以下の条件を満たす必要があります。

  • Cloneを実装している
  • Reqが次のうちいずれかと等しい
  • Service2::Response()と等しい
  • Service2::ErrorInto<Box<dyn Error + Send + Sync + 'static>>を実装している

Trait Implementations§

Source§

impl<Service: Clone> Clone for Handler<Service>

Source§

fn clone(&self) -> Handler<Service>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Service: Debug> Debug for Handler<Service>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Srv, Body> Service<Request<Body>> for Handler<Srv>
where Srv: Service<Event, Response = (), Error = Error> + Clone, Body: Body, Body::Error: Into<Box<dyn Error + Send + Sync + 'static>>,

Source§

type Response = Response<String>

Responses given by the service.
Source§

type Error = Error

Errors produced by the service.
Source§

type Future = HandlerCall<Body, Srv>

The future response value.
Source§

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
Source§

fn call(&mut self, req: Request<Body>) -> Self::Future

Process the request and return the response asynchronously. Read more

Auto Trait Implementations§

§

impl<Service> Freeze for Handler<Service>
where Service: Freeze,

§

impl<Service> RefUnwindSafe for Handler<Service>
where Service: RefUnwindSafe,

§

impl<Service> Send for Handler<Service>
where Service: Send,

§

impl<Service> Sync for Handler<Service>
where Service: Sync,

§

impl<Service> Unpin for Handler<Service>
where Service: Unpin,

§

impl<Service> UnwindSafe for Handler<Service>
where Service: 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, Request> ServiceExt<Request> for T
where T: Service<Request> + ?Sized,

Source§

fn ready(&mut self) -> Ready<'_, Self, Request>
where Self: Sized,

Yields a mutable reference to the service when it is ready to accept a request.
Source§

fn ready_oneshot(self) -> ReadyOneshot<Self, Request>
where Self: Sized,

Yields the service when it is ready to accept a request.
Source§

fn oneshot(self, req: Request) -> Oneshot<Self, Request>
where Self: Sized,

Consume this Service, calling it with the provided request once it is ready.
Source§

fn call_all<S>(self, reqs: S) -> CallAll<Self, S>
where Self: Sized, S: Stream<Item = Request>,

Process all requests from the given Stream, and produce a Stream of their responses. Read more
Source§

fn and_then<F>(self, f: F) -> AndThen<Self, F>
where Self: Sized, F: Clone,

Executes a new future after this service’s future resolves. This does not alter the behaviour of the poll_ready method. Read more
Source§

fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
where Self: Sized, F: FnOnce(Self::Response) -> Response + Clone,

Maps this service’s response value to a different value. This does not alter the behaviour of the poll_ready method. Read more
Source§

fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
where Self: Sized, F: FnOnce(Self::Error) -> Error + Clone,

Maps this service’s error value to a different value. This does not alter the behaviour of the poll_ready method. Read more
Source§

fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
where Self: Sized, Error: From<Self::Error>, F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,

Maps this service’s result type (Result<Self::Response, Self::Error>) to a different value, regardless of whether the future succeeds or fails. Read more
Source§

fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
where Self: Sized, F: FnMut(NewRequest) -> Request,

Composes a function in front of the service. Read more
Source§

fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
where Self: Sized, Error: From<Self::Error>, F: FnOnce(Result<Self::Response, Self::Error>) -> Fut + Clone, Fut: Future<Output = Result<Response, Error>>,

Composes an asynchronous function after this service. Read more
Source§

fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
where Self: Sized, F: FnMut(Self::Future) -> Fut, Error: From<Self::Error>, Fut: Future<Output = Result<Response, Error>>,

Composes a function that transforms futures produced by the service. Read more
Source§

fn boxed(self) -> BoxService<Request, Self::Response, Self::Error>
where Self: Sized + Send + 'static, Self::Future: Send + 'static,

Convert the service into a Service + Send trait object. Read more
Source§

fn boxed_clone(self) -> BoxCloneService<Request, Self::Response, Self::Error>
where Self: Sized + Clone + Send + 'static, Self::Future: Send + 'static,

Convert the service into a Service + Clone + Send trait object. Read more
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.