Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

A client connection to a relay.

Implementations§

Source§

impl Client

Source

pub fn new(relay_url: &str) -> Client

Connect to a relay

Source

pub async fn is_connected(&self) -> bool

Is connected

Source

pub async fn disconnect(&self) -> Result<(), Error>

Disconnect from the relay

Source

pub async fn get_auth_state(&self) -> Result<AuthState, Error>

Get auth state

Source

pub async fn wait_for_auth_state_change( &self, timeout: Duration, ) -> Result<AuthState, Error>

Wait for auth state

Source

pub async fn send_authenticate( &self, challenge: String, signer: Arc<dyn Signer>, reconnect_timeout: Duration, ) -> Result<Id, Error>

Authenticate This does not wait for any reply.

Source

pub async fn full_authenticate( &self, signer: Arc<dyn Signer>, timeout: Duration, ) -> Result<(), Error>

Full Authentication process. Run this when you get “auth-required” in an OK or CLOSED message if you wish to authenticate.

Source

pub async fn post_event( &self, event: Event, reconnect_timeout: Duration, ) -> Result<(), Error>

Post an event to the relay

Source

pub async fn post_raw_event( &self, json: String, reconnect_timeout: Duration, ) -> Result<(), Error>

Post a raw event to the relay

Source

pub async fn post_event_and_wait_for_result( &self, event: Event, timeout: Duration, auth: Option<Arc<dyn Signer>>, ) -> Result<(bool, String), Error>

This posts the event, and waits for the OK result, authenticating if requested if auth is Some.

Source

pub async fn wait_for_ok( &self, id: Id, timeout: Duration, ) -> Result<(bool, String), Error>

Wait for an Ok

Source

pub async fn subscribe( &self, filter: Filter, reconnect_timeout: Duration, ) -> Result<SubscriptionId, Error>

Subscribe to a filter. This does not wait for results.

Source

pub async fn close_subscription( &self, sub_id: SubscriptionId, ) -> Result<(), Error>

Close a subscription

Source

pub async fn wait_for_subscribed_event( &self, sub_id: SubscriptionId, timeout: Duration, ) -> Result<Event, Error>

Wait for an event on the given subscription

Source

pub async fn wait_for_subscribed_event_or_eose( &self, sub_id: SubscriptionId, timeout: Duration, ) -> Result<Option<Event>, Error>

Wait for an event on the given subscription

Source

pub async fn subscribe_and_wait_for_events( &self, filter: Filter, timeout: Duration, signer: Option<Arc<dyn Signer>>, ) -> Result<Vec<Event>, Error>

Subscribe and collect all results up to the EOSE

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.

§

impl<T> Instrument for T

§

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

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

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> 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T