@@ -17,25 +17,38 @@ use bytes::{Bytes, BytesMut};
1717/// This trait describes how to encode a given type.
1818pub trait Encode {
1919 /// Get the length of this type encoded in bytes, prior to Base64 encoding.
20+ ///
21+ /// # Errors
22+ /// Returns errors specific to the concrete implementation of this trait.
2023 fn encoded_len ( & self ) -> Result < usize , Error > ;
2124
2225 /// Encode this value using the provided [`Writer`].
26+ ///
27+ /// # Errors
28+ /// Returns errors specific to the concrete implementation of this trait.
2329 fn encode ( & self , writer : & mut impl Writer ) -> Result < ( ) , Error > ;
2430
25- /// Return the length of this type after encoding when prepended with a
26- /// `uint32` length prefix.
31+ /// Return the length of this type after encoding when prepended with a `uint32` length prefix.
32+ ///
33+ /// # Errors
34+ /// Returns errors specific to the concrete implementation of this trait.
2735 fn encoded_len_prefixed ( & self ) -> Result < usize , Error > {
2836 [ 4 , self . encoded_len ( ) ?] . checked_sum ( )
2937 }
3038
31- /// Encode this value, first prepending a `uint32` length prefix
32- /// set to [`Encode::encoded_len`].
39+ /// Encode this value, first prepending a `uint32` length prefix set to [`Encode::encoded_len`].
40+ ///
41+ /// # Errors
42+ /// Returns errors specific to the concrete implementation of this trait.
3343 fn encode_prefixed ( & self , writer : & mut impl Writer ) -> Result < ( ) , Error > {
3444 self . encoded_len ( ) ?. encode ( writer) ?;
3545 self . encode ( writer)
3646 }
3747
3848 /// Encode this value, returning a `Vec<u8>` containing the encoded message.
49+ ///
50+ /// # Errors
51+ /// Returns errors specific to the concrete implementation of this trait.
3952 #[ cfg( feature = "alloc" ) ]
4053 fn encode_vec ( & self ) -> Result < Vec < u8 > , Error > {
4154 let mut ret = Vec :: with_capacity ( self . encoded_len ( ) ?) ;
@@ -44,6 +57,9 @@ pub trait Encode {
4457 }
4558
4659 /// Encode this value, returning a [`BytesMut`] containing the encoded message.
60+ ///
61+ /// # Errors
62+ /// Returns errors specific to the concrete implementation of this trait.
4763 #[ cfg( feature = "bytes" ) ]
4864 fn encode_bytes ( & self ) -> Result < BytesMut , Error > {
4965 let mut ret = BytesMut :: with_capacity ( self . encoded_len ( ) ?) ;
0 commit comments