@@ -794,13 +794,15 @@ macro_rules! length_delimited {
794
794
pub mod string {
795
795
use super :: * ;
796
796
797
- pub fn encode < B > ( tag : u32 , value : & String , buf : & mut B )
797
+ pub fn encode < S , B > ( tag : u32 , value : & S , buf : & mut B )
798
798
where
799
+ S : AsRef < str > ,
799
800
B : BufMut ,
800
801
{
802
+ let slice = value. as_ref ( ) ;
801
803
encode_key ( tag, WireType :: LengthDelimited , buf) ;
802
- encode_varint ( value . len ( ) as u64 , buf) ;
803
- buf. put_slice ( value . as_bytes ( ) ) ;
804
+ encode_varint ( slice . len ( ) as u64 , buf) ;
805
+ buf. put_slice ( slice . as_bytes ( ) ) ;
804
806
}
805
807
pub fn merge < B > (
806
808
wire_type : WireType ,
@@ -876,21 +878,16 @@ pub mod string {
876
878
pub trait BytesAdapter : sealed:: BytesAdapter { }
877
879
878
880
mod sealed {
879
- use super :: { Buf , BufMut } ;
881
+ use super :: Buf ;
880
882
881
- pub trait BytesAdapter : Default + Sized + ' static {
883
+ pub trait BytesAdapter : Default + Sized + AsRef < [ u8 ] > + ' static {
882
884
fn len ( & self ) -> usize ;
883
885
884
886
/// Replace contents of this buffer with the contents of another buffer.
885
887
fn replace_with < B > ( & mut self , buf : B )
886
888
where
887
889
B : Buf ;
888
890
889
- /// Appends this buffer to the (contents of) other buffer.
890
- fn append_to < B > ( & self , buf : & mut B )
891
- where
892
- B : BufMut ;
893
-
894
891
fn is_empty ( & self ) -> bool {
895
892
self . len ( ) == 0
896
893
}
@@ -910,13 +907,6 @@ impl sealed::BytesAdapter for Bytes {
910
907
{
911
908
* self = buf. copy_to_bytes ( buf. remaining ( ) ) ;
912
909
}
913
-
914
- fn append_to < B > ( & self , buf : & mut B )
915
- where
916
- B : BufMut ,
917
- {
918
- buf. put ( self . clone ( ) )
919
- }
920
910
}
921
911
922
912
impl BytesAdapter for Vec < u8 > { }
@@ -934,26 +924,20 @@ impl sealed::BytesAdapter for Vec<u8> {
934
924
self . reserve ( buf. remaining ( ) ) ;
935
925
self . put ( buf) ;
936
926
}
937
-
938
- fn append_to < B > ( & self , buf : & mut B )
939
- where
940
- B : BufMut ,
941
- {
942
- buf. put ( self . as_slice ( ) )
943
- }
944
927
}
945
928
946
929
pub mod bytes {
947
930
use super :: * ;
948
931
949
932
pub fn encode < A , B > ( tag : u32 , value : & A , buf : & mut B )
950
933
where
951
- A : BytesAdapter ,
934
+ A : AsRef < [ u8 ] > ,
952
935
B : BufMut ,
953
936
{
937
+ let slice = value. as_ref ( ) ;
954
938
encode_key ( tag, WireType :: LengthDelimited , buf) ;
955
- encode_varint ( value . len ( ) as u64 , buf) ;
956
- value . append_to ( buf ) ;
939
+ encode_varint ( slice . len ( ) as u64 , buf) ;
940
+ buf . put_slice ( slice ) ;
957
941
}
958
942
959
943
pub fn merge < A , B > (
0 commit comments