Skip to main content

Net

Struct Net 

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

A node on the Net mesh.

This is the main SDK handle. Every computer, device, and application is a Net node — there are no clients, no servers, no coordinators.

§Example

use net_sdk::{Net, Backpressure};

let node = Net::builder()
    .shards(4)
    .backpressure(Backpressure::DropOldest)
    .memory()
    .build()
    .await?;

node.emit(&serde_json::json!({"token": "hello"}))?;

let response = node.poll(net_sdk::PollRequest { limit: 100, ..Default::default() }).await?;
for event in &response.events {
    println!("{}", event.raw_str().unwrap_or("<non-utf8>"));
}

node.shutdown().await?;

Implementations§

Source§

impl Net

Source

pub fn builder() -> NetBuilder

Create a builder for configuring a new node.

Source

pub fn from_bus(bus: EventBus) -> Self

Create a node from an existing EventBus.

Source

pub fn emit<T: Serialize>(&self, event: &T) -> Result<Receipt>

Emit a serializable event.

Serializes T to JSON via serde and ingests it.

Source

pub fn emit_raw(&self, bytes: impl Into<Bytes>) -> Result<Receipt>

Emit raw bytes (fastest path).

Source

pub fn emit_str(&self, json: &str) -> Result<Receipt>

Emit a raw JSON string.

Source

pub fn emit_batch<T: Serialize>(&self, events: &[T]) -> Result<usize>

Emit a batch of serializable events. Returns the number ingested.

Source

pub fn emit_raw_batch(&self, events: Vec<Bytes>) -> usize

Emit a batch of raw byte events. Returns the number ingested.

Source

pub async fn poll(&self, request: PollRequest) -> Result<PollResponse>

One-shot poll for events.

Source

pub fn subscribe(&self, opts: SubscribeOpts) -> EventStream

Subscribe to a stream of events.

Returns an async Stream that yields events with adaptive backoff.

Source

pub fn subscribe_typed<T: DeserializeOwned>( &self, opts: SubscribeOpts, ) -> TypedEventStream<T>

Subscribe to a typed stream of events.

Each event is automatically deserialized into T.

Source

pub fn stats(&self) -> Stats

Get ingestion statistics.

Source

pub fn shards(&self) -> u16

Get the number of active shards.

Source

pub async fn health(&self) -> bool

Check if the node is healthy.

Source

pub async fn flush(&self) -> Result<()>

Flush all pending batches to the adapter.

Source

pub async fn shutdown(self) -> Result<()>

Gracefully shut down the node.

Drains pending events through the adapter and signals all background tasks to exit. Safe to call even when other Arc<EventBus> clones exist (e.g. an outstanding EventStream from subscribe): EventBus::shutdown_via_ref is idempotent and reference-based, so the shutdown work runs regardless of strong-ref count, and outstanding clones observe the bus as shut down on their next operation.

Source

pub fn bus(&self) -> &EventBus

Get a reference to the underlying EventBus.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Net

§

impl !UnwindSafe for Net

§

impl Freeze for Net

§

impl Send for Net

§

impl Sync for Net

§

impl Unpin for Net

§

impl UnsafeUnpin for Net

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