Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/traits/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,19 @@ impl CodecConfig for DefaultCodecConfig {
/// Trait for decoding bytes into a type with configuration.
pub trait Decode: Sized {
/// Decode from bytes using the given configuration.
///
/// # Errors
///
/// Returns [`CodecError`] if decoding fails due to invalid data,
/// size limits exceeded, or other configuration violations.
fn decode<C: CodecConfig>(bytes: &[u8], config: &C) -> Result<Self, CodecError>;

/// Decode from Bytes using the given configuration.
///
/// # Errors
///
/// Returns [`CodecError`] if decoding fails due to invalid data,
/// size limits exceeded, or other configuration violations.
fn decode_bytes<C: CodecConfig>(bytes: &Bytes, config: &C) -> Result<Self, CodecError> {
Self::decode(bytes.as_ref(), config)
}
Expand All @@ -121,9 +131,17 @@ pub trait Decode: Sized {
/// Trait for encoding a type into bytes.
pub trait Encode {
/// Encode into bytes.
///
/// # Errors
///
/// Returns [`CodecError`] if encoding fails.
fn encode(&self) -> Result<Bytes, CodecError>;

/// Encode into a `Vec<u8>`.
///
/// # Errors
///
/// Returns [`CodecError`] if encoding fails.
fn encode_vec(&self) -> Result<Vec<u8>, CodecError> {
self.encode().map(|b| b.to_vec())
}
Expand Down
4 changes: 4 additions & 0 deletions crates/traits/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ impl<T> Handle<T> {
}

/// Wait for the task to complete.
///
/// # Errors
///
/// Returns [`JoinError`] if the task was cancelled or panicked.
pub async fn join(self) -> Result<T, JoinError> {
self.inner.await.map_err(JoinError)
}
Expand Down
Loading