@@ -76,3 +76,62 @@ impl fmt::Display for BulkString {
7676 f. write_str ( String :: from_utf8_lossy ( & self . 0 ) . as_ref ( ) )
7777 }
7878}
79+
80+ /// Represents a reference to the [Bulk String](https://redis.io/docs/reference/protocol-spec/#resp-bulk-strings) RESP type
81+ #[ derive( Serialize , Hash , PartialEq , Eq , Clone ) ]
82+ pub struct RefBulkString < ' a > (
83+ #[ serde(
84+ serialize_with = "serialize_byte_buf"
85+ ) ]
86+ & ' a [ u8 ] ,
87+ ) ;
88+
89+ impl < ' a > RefBulkString < ' a > {
90+ /// Constructs a new `RefBulkString` from a byte slice
91+ #[ inline]
92+ pub fn new ( bytes : & ' a [ u8 ] ) -> Self {
93+ Self ( bytes)
94+ }
95+
96+ /// Returns the internal buffer as a byte slice
97+ #[ inline]
98+ pub fn as_bytes ( & self ) -> & [ u8 ] {
99+ self . 0
100+ }
101+ }
102+
103+ impl < ' a > Deref for RefBulkString < ' a > {
104+ type Target = [ u8 ] ;
105+
106+ #[ inline]
107+ fn deref ( & self ) -> & Self :: Target {
108+ self . 0
109+ }
110+ }
111+
112+ impl < ' a > From < & ' a [ u8 ] > for RefBulkString < ' a > {
113+ #[ inline]
114+ fn from ( bytes : & ' a [ u8 ] ) -> Self {
115+ Self ( bytes)
116+ }
117+ }
118+
119+ impl < ' a , const N : usize > From < & ' a [ u8 ; N ] > for RefBulkString < ' a > {
120+ #[ inline]
121+ fn from ( bytes : & ' a [ u8 ; N ] ) -> Self {
122+ Self ( bytes. as_slice ( ) )
123+ }
124+ }
125+
126+ impl < ' a > fmt:: Debug for RefBulkString < ' a > {
127+ #[ inline]
128+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129+ f. debug_tuple ( "RefBulkString" ) . field ( & self . 0 ) . finish ( )
130+ }
131+ }
132+
133+ impl < ' a > fmt:: Display for RefBulkString < ' a > {
134+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
135+ f. write_str ( String :: from_utf8_lossy ( self . 0 ) . as_ref ( ) )
136+ }
137+ }
0 commit comments