pub struct ServerBuilder { /* private fields */ }
Expand description
ServerBuilder
is used to first register closures to events before finally building a
tide::Server
using those closures.
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn on<E: Into<Event>>(
self,
event: E,
handler: impl Fn(Payload) + Send + Sync + 'static,
) -> Self
pub fn on<E: Into<Event>>( self, event: E, handler: impl Fn(Payload) + Send + Sync + 'static, ) -> Self
Registers the given event handler to be run when the given event is received.
The event handler receives a Payload
as the single argument. Since webhooks are
generally passively consumed (Github will not meaningfully (to us) process our response),
the handler returns only a ()
. As far as the event dispatcher is concerned, all the
meaningful work will be done as side-effects of the closures you register here.
The types involved here are not stable yet due to ongoing API development.
§Example
let github = tide_github::new("my webhook s3ct#t")
.on(Event::IssueComment, |payload| {
println!("Got payload for repository {}", payload.repository.name)
});
Sourcepub fn build(self) -> Server<()>
pub fn build(self) -> Server<()>
Build a tide::Server
using the registered events.
Since the API is still in development, in the future we might instead (or additionally)
expose the EventHandlerDispatcher
directly.