pub struct Server { /* private fields */ }Expand description
An instance of a Perspective server. Each Server instance is separate,
and does not share perspective_client::Table (or other) data with other
Servers.
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(
on_poll_request: Option<Arc<dyn Fn(&Server) -> BoxFuture<'static, Result<(), ServerError>> + Send + Sync>>,
) -> Self
pub fn new( on_poll_request: Option<Arc<dyn Fn(&Server) -> BoxFuture<'static, Result<(), ServerError>> + Send + Sync>>, ) -> Self
Create a new Server.
§Arguments
on_poll_requestA callback function which theServerwill invoke when there are updates that need to be flushed, after which you must eventually callServer::poll(or else no updates will be processed). This optimization allows batching updates, depending on context.
Sourcepub async fn new_session_with_callback<F>(
&self,
send_response: F,
) -> LocalSession
pub async fn new_session_with_callback<F>( &self, send_response: F, ) -> LocalSession
An alternative method for creating a new [Session] for this
Server, from a callback closure instead of a via a trait.
See Server::new_session for details.
§Arguments
send_response- A function invoked by theServerwhen a response message needs to be sent to theperspective_client::Client.
Sourcepub async fn new_session<F>(&self, session_handler: F) -> LocalSession
pub async fn new_session<F>(&self, session_handler: F) -> LocalSession
Create a [Session] for this Server, suitable for exactly one
perspective_client::Client (not necessarily in this process). A
[Session] represents the server-side state of a single
client-to-server connection.
§Arguments
session_handler- An implementor ofSessionHandlerwhich will be invoked by theServerwhen a response message needs to be sent to the [Client]. The response itself should be passed to [Client::handle_response] eventually, though it may-or-may-not be in the same process.
Sourcepub fn new_local_client(&self) -> LocalClient
pub fn new_local_client(&self) -> LocalClient
Create a new [Client] instance bound to this Server directly.
Sourcepub async fn poll(&self) -> Result<(), ServerError>
pub async fn poll(&self) -> Result<(), ServerError>
Flush any pending messages which may have resulted from previous
[Session::handle_request] calls.
Server::poll only needs to be called if you’ve implemented
a custom Perspective Server and provided the on_poll_request
constructor keyword argument.
Calling [Session::poll] may result in the send_response parameter
which was used to construct this (or other) [Session] to fire.
Whenever a [Session::handle_request] method is invoked for a
perspective_server::Server, at least one [Session::poll] should be
scheduled to clear other clients message queues.
poll() must be called after [Table::update] or [Table::remove]
and on_poll_request is notified, or the changes will not be applied.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl !UnwindSafe for Server
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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