Skip to main content

ProtocolConfigBuilder

Struct ProtocolConfigBuilder 

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

Builder for ProtocolConfig with a fluent API.

Implementations§

Source§

impl ProtocolConfigBuilder

Source

pub fn new(app_id: impl Into<String>, profile: impl Into<String>) -> Self

Creates a new builder.

Source

pub fn transport(self, config: TransportConfig) -> Self

Configures transports.

Source

pub fn ble_enabled(self, enabled: bool) -> Self

Enables or disables BLE transport.

Source

pub fn wifi_direct_enabled(self, enabled: bool) -> Self

Enables or disables Wi-Fi Direct transport.

Source

pub fn internet_enabled(self, enabled: bool) -> Self

Enables or disables Internet transport.

Source

pub fn nostr_enabled(self, enabled: bool) -> Self

Enables or disables Nostr relay transport.

Source

pub fn nostr_sealing_enabled(self, enabled: bool) -> Self

Enables or disables sealing of outgoing Nostr frames (default on).

Source

pub fn nostr_username_discovery_enabled(self, enabled: bool) -> Self

Enables username discovery publication and resolution (default off; see TransportConfig::nostr_username_discovery_enabled).

Source

pub fn nostr_cold_contact_enabled(self, enabled: bool) -> Self

Enables or disables Nostr key-package publication and peer resolution (default on; see TransportConfig::nostr_cold_contact_enabled).

Source

pub fn dors(self, config: DorsConfig) -> Self

Configures DORS (Dynamic Offline Relay Switch).

Source

pub fn online_first(self, enabled: bool) -> Self

Enables online-first mode (prefer Internet when available).

Source

pub fn relay(self, config: RelayConfig) -> Self

Configures relay management.

Source

pub fn mesh_relay(self, config: MeshRelayConfig) -> Self

Configures how traffic is carried for other people.

Source

pub fn reliability(self, config: ReliabilityConfig) -> Self

Configures reliability layer.

Source

pub fn initial_ttl(self, ttl: u8) -> Self

Sets the initial TTL for messages.

Source

pub fn encryption(self, config: EncryptionConfig) -> Self

Configures encryption settings.

Source

pub fn encryption_enabled(self, enabled: bool) -> Self

Enables or disables automatic encryption.

Source

pub fn auto_key_exchange(self, enabled: bool) -> Self

Enables or disables automatic key exchange on peer discovery.

Source

pub fn store_pending_messages(self, enabled: bool) -> Self

Enables or disables storing pending messages for later encryption.

Source

pub fn require_encryption(self, required: bool) -> Self

Enables or disables strict encryption requirement.

Source

pub fn pending_queue(self, config: PendingQueueConfig) -> Self

Configures pending encrypted message queue bounds and overflow behavior.

Source

pub fn group(self, config: GroupConfig) -> Self

Configures group messaging settings.

Source

pub fn max_group_members(self, max: usize) -> Self

Sets the maximum number of members allowed in a single group.

Source

pub fn group_relay_enabled(self, enabled: bool) -> Self

Sets whether groups should attempt relay server registration.

Source

pub fn group_relay_broadcast_enabled(self, enabled: bool) -> Self

Sets whether relay-synced groups may send via a single relay broadcast instead of per-member fan-out. See GroupConfig::relay_broadcast_enabled — on by default, but only ever taken against a relay that advertised the group_delivery_v3 capability, whose settled, address-space delivery report gives the broadcast a per-recipient delivery contract.

Source

pub fn group_enforce_admin_commits(self, enabled: bool) -> Self

Sets whether unauthorized MLS membership commits are refused rather than applied-and-reported. See GroupConfig::enforce_admin_commits — off by default, and enabling it risks permanently forking members whose admin overlay disagrees.

Source

pub fn security(self, config: SecurityConfig) -> Self

Configures security settings.

Source

pub fn require_transport_identity(self, required: bool) -> Self

Sets whether transport identity is required for control messages.

Source

pub fn data(self, config: DataConfig) -> Self

Configures the replicated-document data layer.

Source

pub fn data_enabled(self, enabled: bool) -> Self

Sets whether the data layer accepts work. See DataConfig::enabled.

Source

pub fn data_storage(self, storage: Arc<dyn ProtocolStateStorage>) -> Self

Points documents at a storage backend of the application’s choosing.

The whole bring-your-own-backend path, in one call. See DataConfig::storage, including what it means for logout.

Source

pub fn build(self) -> Result<ProtocolConfig>

Builds and validates the configuration.

§Returns

Returns Ok(ProtocolConfig) if valid, Err otherwise.

Examples found in repository?
examples/replicated_notes.rs (line 83)
74fn main() -> Result<(), Box<dyn std::error::Error>> {
75    // Both stores outlive the engine below, which is what makes the reopen at
76    // the end a reopen rather than a fresh start. The secure store matters as
77    // much as the record store: documents are sealed with a key that lives in
78    // it, so dropping only that half looks exactly like data loss.
79    let secure = Arc::new(InMemoryStorage::default());
80    let records = Arc::new(MemoryStateStorage::default());
81
82    // `data.enabled` defaults to true, so nothing here switches the layer on.
83    let config = ProtocolConfig::builder("com.example.notes", "default").build()?;
84    let mut protocol = OfflineProtocol::new(config)?;
85
86    // Documents are sealed at rest and the record key is minted here, so this
87    // call is the prerequisite for every method below.
88    protocol.initialize_mls(secure.clone(), records.clone())?;
89
90    // A space is an MLS scope: a peer's address for a 1:1 space, or the group
91    // id for a group. Nothing replicates in this example, so the name only
92    // has to be a valid one.
93    let space = "demo-space";
94
95    protocol.data_create_doc(space, "trip")?;
96
97    // A map: last writer wins per key, and different keys never conflict.
98    protocol.data_map_set(
99        space,
100        "trip",
101        "meta",
102        "title",
103        DataValue::Text {
104            value: "Coast road".to_string(),
105        },
106    )?;
107
108    // A list: concurrent insertions both survive, in a deterministic order.
109    for item in ["water", "map", "torch"] {
110        protocol.data_list_push(
111            space,
112            "trip",
113            "packing",
114            DataValue::Text {
115                value: item.to_string(),
116            },
117        )?;
118    }
119
120    // Text: character-level merge, so two people typing in one paragraph keep
121    // both sets of words. Positions are character offsets, not byte offsets.
122    protocol.data_text_insert(space, "trip", "notes", 0, "Meet at the bridge")?;
123
124    // A counter: increments add up rather than overwriting each other.
125    protocol.data_counter_increment(space, "trip", "opened", 1.0)?;
126
127    // Edits batch before they reach storage. This is the call that makes them
128    // durable, and `data_changed` fires after the same point, never before.
129    protocol.data_flush(space, "trip")?;
130
131    println!("spaces:    {:?}", protocol.data_list_spaces()?);
132    println!("documents: {:?}", protocol.data_list_docs(space)?);
133    println!(
134        "compacted: {} bytes",
135        protocol.data_doc_size(space, "trip")?
136    );
137    println!(
138        "history:   {} bytes",
139        protocol.data_export_raw(space, "trip")?.len()
140    );
141    println!("json:      {}", protocol.data_doc_json(space, "trip")?);
142
143    // Both halves of the escape hatch are above: `data_doc_json` is the plain
144    // JSON of the current state, `data_export_raw` the engine-native history.
145    // An application can always take its data and leave.
146
147    // Reopen: a new engine over the same two stores. The records were sealed
148    // by the first one and are read back by the second, which is the property
149    // an application depends on across a restart.
150    drop(protocol);
151    let config = ProtocolConfig::builder("com.example.notes", "default").build()?;
152    let mut reopened = OfflineProtocol::new(config)?;
153    reopened.initialize_mls(secure, records)?;
154
155    println!("after reopen");
156    println!(
157        "  title:   {:?}",
158        reopened.data_map_get(space, "trip", "meta", "title")?
159    );
160    println!(
161        "  packing: {}",
162        reopened.data_list_len(space, "trip", "packing")?
163    );
164    println!(
165        "  notes:   {:?}",
166        reopened.data_text_value(space, "trip", "notes")?
167    );
168    println!(
169        "  opened:  {}",
170        reopened.data_counter_value(space, "trip", "opened")?
171    );
172
173    Ok(())
174}

Auto Trait Implementations§

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> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Paint for T
where T: ?Sized,

Source§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
Source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
Source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
Source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
Source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
Source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
Source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
Source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
Source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
Source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
Source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
Source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
Source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
Source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
Source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
Source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
Source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
Source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
Source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
Source§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
Source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
Source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
Source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
Source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
Source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
Source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
Source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
Source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
Source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
Source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
Source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
Source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
Source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
Source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
Source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
Source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
Source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
Source§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling Attribute value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
Source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
Source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
Source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
Source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
Source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
Source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
Source§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi Quirk value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
Source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
Source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
Source§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1:

renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
Source§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
Source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
Source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
Source§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the Condition value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
Source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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