Skip to main content

Mesh

Struct Mesh 

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

Represents a mesh::Node with the ability to spawn new processes that can communicate with any other process belonging to the same mesh.

§Process creation

A Mesh instance can spawn new processes with an initial communication channel associated with the mesh. All processes originating from the same mesh can potentially communicate and exchange channels with each other.

Each spawned process can be configured differently via ProcessConfig. Processes are created with Mesh::launch_host.

let mesh = Mesh::new("remote_mesh".to_string()).unwrap();
let (send, recv) = mesh::channel();
mesh.launch_host(ProcessConfig::new("test"), recv).await.unwrap();
send.send(String::from("message for new process"));

Implementations§

Source§

impl Mesh

Source

pub fn new(mesh_name: String) -> Result<Self>

Creates a new mesh with the given name.

Source

pub async fn launch_host<T: 'static + MeshField + Send>( &self, config: ProcessConfig, initial_message: T, ) -> Result<i32>

Spawns a new host in the mesh with the provided configuration and initial message.

The initial message will be provided to the closure passed to try_run_mesh_host().

Returns the process ID of the launched host.

Source

pub async fn shutdown(self)

Shutdown the mesh and wait for any spawned processes to exit.

The Mesh instance is no longer usable after shutdown.

Source

pub fn crash(&self, pid: i32)

Crashes the child process with the given process ID.

Source

pub async fn listen<T: 'static + MeshField + Send>( &self, path: &Path, ) -> Result<Listener<T>>

Listen for mesh connections on a Unix socket.

Returns a Listener<T> that yields items from connecting clients. Each client gets a Sender<T> bridged to this listener’s queue. Dropping the Listener stops accepting new connections.

§Security

The socket at path is an external entry point for other local processes to join the mesh. On Unix, path must reside in a directory accessible only to the intended user (e.g. mode 0700). On Windows, the socket’s parent directory should be ACL’d to restrict access. Any local user who can connect to the socket can join the mesh.

Trait Implementations§

Source§

impl Inspect for Mesh

Source§

fn inspect(&self, req: Request<'_>)

Inspects the object.

Auto Trait Implementations§

§

impl Freeze for Mesh

§

impl !RefUnwindSafe for Mesh

§

impl Send for Mesh

§

impl Sync for Mesh

§

impl Unpin for Mesh

§

impl UnsafeUnpin for Mesh

§

impl !UnwindSafe for Mesh

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