Skip to main content

Crate xmtp_common

Crate xmtp_common 

Source
Expand description

Common types shared among all XMTP Crates

Re-exports§

pub use retry::*;
pub use wasm::*;
pub use stream_handles::*;
pub use const::*;

Modules§

const
fmt
hex
retry
A retry strategy that works with rusts native std::error::Error type.
snippet
stream_handles
Consistent Stream behavior between WebAssembly and Native utilizing tokio::task::spawn in native and wasm_bindgen_futures::spawn for web.
time
Time primitives for native and WebAssembly
types
Common Primitive Types that may be shared across all XMTP Crates Types should not have any dependencies other than std and std-adjacent crates (like bytes)
wasm

Macros§

if_d14n
Convenience macro to easily export items for d14n
if_dev
Feature flag for dev network
if_local
if_native
Convenience macro to easily export items for native
if_not_test
if_only_test
if_test
if_v3
Convenience macro to easily export items for d14n
if_wasm
Convenience macro to easily export items for wasm
log_event
optify
Turn the Result<T, E> into an Option<T>, logging the error with tracing::error and returning None if the value matches on Result::Err(). Optionally pass a message as the second argument.
retry_async
Retry but for an async context
retryable
wasm_or_native
wasm_or_native_expr
Convenience macro to easily evaluate an expression for wasm or native

Structs§

EventMetadata
Metadata about a log event variant, including its doc comment and required context fields. This struct is used by proc macros to access event metadata at compile time.

Enums§

Event

Traits§

ErrorCode
A trait for errors that have a unique, stable error code.
Sha2Digest
Convenience wrapper trait covering functionality of cryptographic hash functions with fixed output size.

Functions§

is_structured_logging
Returns true if structured (JSON) logging is enabled. When true, context should not be embedded in the message to avoid duplication. Initializes from environment on first call, then caches the result.
rand_array
rand_secret
rand_string
rand_vec
rng
seeded_rng
sha256_array
Compute the SHA-256 hash of bytes and return it as a fixed [u8; 32], avoiding the heap allocation done by sha256_bytes.
sha256_bytes
Sha256 is used in places where cryptographic security is not required, as sha256 has a significant speed improvement over Keccak.

Type Aliases§

Sha256Digest
SHA-256 hasher.

Attribute Macros§

async_trait
A proc macro attribute that wraps the input in an async_trait implementation, delegating to the appropriate async_trait implementation based on the target architecture.
db_span
Instrument an xmtp_db query method as operation = "db.<fn_name>" in libxmtp’s canonical, OTEL-safe span form (err, skip_all). Surfaces as xmtp.db.* Collector metrics. See [span] for the shared rationale.
err_span
Error-case-only tracing for an FFI-exported fn: #[tracing::instrument(level = "trace", skip_all, err)].
mls_span
Instrument a high-level MLS operation as operation = "mls.<fn_name>" in libxmtp’s canonical, OTEL-safe span form (err, skip_all). Surfaces as xmtp.mls.* Collector metrics. See [span] for the shared rationale.
rpc_span
Instrument an ApiClientWrapper RPC method as operation = "rpc.<fn_name>" in libxmtp’s canonical, OTEL-safe span form (err, skip_all). Surfaces as xmtp.api.* Collector metrics. See [span] for the shared rationale.
span
Instrument a method as a telemetry operation span in libxmtp’s single canonical, OTEL-safe form: #[tracing::instrument(err, skip_all, fields(operation = "<prefix>.<fn_name>"))].
timeout
Attribute macro that wraps an async test body with a WASM-compatible timeout.

Derive Macros§

ErrorCode
Derive macro for the ErrorCode trait.