#[non_exhaustive]pub struct ConnectOptions {
pub replica_id: String,
pub from: FeedPosition,
pub timeout: Duration,
pub security: Option<ReplicaSecurity>,
}Expand description
Everything a replica presents when it connects, beyond the address. The defaults are a fresh replica: generation 0 (no continuity claim), offset 0, a 5 s connect timeout, a plaintext link.
use std::time::Duration;
use kevy_replicate::feed::FeedPosition;
use kevy_replicate::replica::ConnectOptions;
let opts = ConnectOptions::new("replica-a")
.with_from(FeedPosition::new(7, 42))
.with_timeout(Duration::from_secs(1));
assert_eq!(opts.from, FeedPosition::new(7, 42));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.replica_id: StringThe replica’s identifier, operator-set; the primary keys its slot by it.
use kevy_replicate::handshake::HandshakeReq;
use kevy_replicate::replica::{ConnectOptions, ReplicaClient};
drop(ReplicaClient::connect_with(addr, &ConnectOptions::new("replica-a"))?);
// the primary sees the id in the handshake
let sent = primary.join().expect("primary thread");
let mut argv = kevy_resp::Argv::default();
kevy_resp::parse_command_into(&sent, &mut argv)?;
assert_eq!(HandshakeReq::parse(&argv)?.replica_id, "replica-a");from: FeedPositionWhere to resume: the feed generation this replica’s data reflects
(0 = unknown or fresh) and the offset within it. The primary
serves the offset’s continuity only when the generations match;
otherwise it ships a snapshot.
use kevy_replicate::feed::FeedPosition;
use kevy_replicate::replica::{ConnectOptions, ReplicaClient};
let opts = ConnectOptions::new("replica-a").with_from(FeedPosition::new(7, 42));
let client = ReplicaClient::connect_with(addr, &opts)?;
assert_eq!(client.expected_offset(), opts.from.offset); // resumes where its data endstimeout: DurationHow long the connect and the handshake may take.
use std::time::Duration;
use kevy_replicate::replica::{ConnectOptions, ReplicaClient, ReplicaError};
// a listener that never answers the handshake
let silent = std::net::TcpListener::bind("127.0.0.1:0")?;
let opts = ConnectOptions::new("replica-a").with_timeout(Duration::from_millis(50));
let err = ReplicaClient::connect_with(silent.local_addr()?, &opts).unwrap_err();
assert!(matches!(err, ReplicaError::Io(_)));security: Option<ReplicaSecurity>Some to open a Noise IK link instead of a plaintext one.
use kevy_replicate::replica::{ConnectOptions, ReplicaSecurity};
assert!(ConnectOptions::new("r1").security.is_none()); // plaintext by default
let sec = ReplicaSecurity::new(kevy_noise::Keypair::from_secret([2; 32]), [9; 32]);
let opts = ConnectOptions::new("r1").with_security(sec);
assert_eq!(opts.security.map(|s| s.primary_key), Some([9; 32]));Implementations§
Source§impl ConnectOptions
impl ConnectOptions
Sourcepub fn new(replica_id: impl Into<String>) -> Self
pub fn new(replica_id: impl Into<String>) -> Self
A fresh replica named replica_id, with the defaults above.
let opts = kevy_replicate::replica::ConnectOptions::new("r1");
assert_eq!(opts.from, kevy_replicate::feed::FeedPosition::default());Sourcepub fn with_from(self, from: FeedPosition) -> Self
pub fn with_from(self, from: FeedPosition) -> Self
Set ConnectOptions::from.
use kevy_replicate::feed::FeedPosition;
let opts = kevy_replicate::replica::ConnectOptions::new("r1").with_from(FeedPosition::new(3, 9));
assert_eq!(opts.from, FeedPosition::new(3, 9));Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
use std::time::Duration;
let opts = kevy_replicate::replica::ConnectOptions::new("r1").with_timeout(Duration::from_secs(1));
assert_eq!(opts.timeout, Duration::from_secs(1));Sourcepub fn with_security(self, security: ReplicaSecurity) -> Self
pub fn with_security(self, security: ReplicaSecurity) -> Self
Open the link under Noise IK with security.
use kevy_replicate::replica::{ConnectOptions, ReplicaSecurity};
let sec = ReplicaSecurity::new(kevy_noise::Keypair::from_secret([2; 32]), [9; 32]);
let opts = ConnectOptions::new("r1").with_security(sec);
assert!(opts.security.is_some());Trait Implementations§
Source§impl Clone for ConnectOptions
impl Clone for ConnectOptions
Auto Trait Implementations§
impl Freeze for ConnectOptions
impl RefUnwindSafe for ConnectOptions
impl Send for ConnectOptions
impl Sync for ConnectOptions
impl Unpin for ConnectOptions
impl UnsafeUnpin for ConnectOptions
impl UnwindSafe for ConnectOptions
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
Mutably borrows from an owned value. Read more