pub struct MailboxConnection<V: Serialize + Send + Sync + 'static> { /* private fields */ }Expand description
Establishing Wormhole connection
You can send and receive arbitrary messages in form of byte slices over it, using Wormhole::send and Wormhole::receive.
Everything else (including encryption) will be handled for you.
To create a wormhole, use the mailbox connection created via MailboxConnection::create or MailboxConnection::connect with the Wormhole::connect method.
Typically, the sender side connects without a code (which will create one), and the receiver side has one (the user entered it, who got it from the sender).
§Clean shutdown
TODO
A MailboxConnection contains a RendezvousServer which is connected to the mailbox
Implementations§
Source§impl<V: Serialize + Send + Sync + 'static> MailboxConnection<V>
impl<V: Serialize + Send + Sync + 'static> MailboxConnection<V>
Sourcepub async fn create(
config: AppConfig<V>,
code_length: usize,
) -> Result<Self, WormholeError>
pub async fn create( config: AppConfig<V>, code_length: usize, ) -> Result<Self, WormholeError>
Create a connection to a mailbox which is configured with a Code starting with the nameplate and by a given number of wordlist based random words.
§Arguments
config: Application configurationcode_length: number of words used for the password. The words are taken from the default wordlist.
§Examples
use magic_wormhole::{AppConfig, MailboxConnection, transfer::APP_CONFIG};
let config = APP_CONFIG;
let mailbox_connection = MailboxConnection::create(config, 2).await?;Sourcepub async fn create_with_password(
config: AppConfig<V>,
password: Password,
) -> Result<Self, WormholeError>
pub async fn create_with_password( config: AppConfig<V>, password: Password, ) -> Result<Self, WormholeError>
Create a connection to a mailbox which is configured with a Code containing the nameplate and the given password.
§Arguments
config: Application configurationpassword: Free text password which will be appended to the nameplate number to form theCode
§Examples
use magic_wormhole::{MailboxConnection, transfer::APP_CONFIG};
let config = APP_CONFIG;
let mailbox_connection =
MailboxConnection::create_with_password(config, "secret".parse()?).await?;TODO: Replace this with create_with_validated_password
Sourcepub async fn connect(
config: AppConfig<V>,
code: Code,
allocate: bool,
) -> Result<Self, WormholeError>
pub async fn connect( config: AppConfig<V>, code: Code, allocate: bool, ) -> Result<Self, WormholeError>
Create a connection to a mailbox defined by a Code which contains the Nameplate and the password to authorize the access.
§Arguments
config: Application configurationcode: TheCoderequired to authorize to connect to an existing mailbox.allocate:true: Allocates aNameplateif it does not exist.false: The call fails with aWormholeError::UnclaimedNameplatewhen theNameplatedoes not exist.
§Examples
use magic_wormhole::{Code, MailboxConnection, Nameplate, transfer::APP_CONFIG};
let config = APP_CONFIG;
let code = "5-password".parse()?;
let mailbox_connection = MailboxConnection::connect(config, code, false).await?;Sourcepub async fn shutdown(self, mood: Mood) -> Result<(), WormholeError>
pub async fn shutdown(self, mood: Mood) -> Result<(), WormholeError>
Shut down the connection to the mailbox
§Arguments
mood:Moodshould give a hint of the reason of the shutdown
§Examples
return async_io::block_on(async {
use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection, Mood};
let config = APP_CONFIG;
let mailbox_connection = MailboxConnection::create_with_password(config, "secret-code-password".parse()?)
.await?;
mailbox_connection.shutdown(Mood::Happy).await?;Auto Trait Implementations§
impl<V> Freeze for MailboxConnection<V>where
V: Freeze,
impl<V> !RefUnwindSafe for MailboxConnection<V>
impl<V> Send for MailboxConnection<V>
impl<V> Sync for MailboxConnection<V>
impl<V> Unpin for MailboxConnection<V>where
V: Unpin,
impl<V> UnsafeUnpin for MailboxConnection<V>where
V: UnsafeUnpin,
impl<V> !UnwindSafe for MailboxConnection<V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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