|
146 | 146 | //! to create codecs to encode prefixes when possible instead of using a slice of bytes. |
147 | 147 | //! |
148 | 148 | //! ``` |
149 | | -//! use std::borrow::Cow; |
150 | 149 | //! use std::convert::Infallible; |
151 | 150 | //! use std::error::Error; |
152 | 151 | //! use std::fs; |
153 | 152 | //! use std::path::Path; |
154 | 153 | //! |
155 | 154 | //! use heed::types::*; |
156 | | -//! use heed::{BoxedError, BytesDecode, ToBytes, Database, EnvOpenOptions}; |
| 155 | +//! use heed::{BoxedError, BytesDecode, BytesEncode, Database, EnvOpenOptions}; |
157 | 156 | //! |
158 | 157 | //! #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
159 | 158 | //! pub enum Level { |
|
170 | 169 | //! |
171 | 170 | //! pub struct LogKeyCodec; |
172 | 171 | //! |
173 | | -//! impl<'a> ToBytes<'a> for LogKeyCodec { |
174 | | -//! type SelfType = LogKey; |
| 172 | +//! impl<'a> BytesEncode<'a> for LogKeyCodec { |
| 173 | +//! type EItem = LogKey; |
175 | 174 | //! |
176 | 175 | //! type ReturnBytes = [u8; 5]; |
177 | 176 | //! |
178 | 177 | //! type Error = Infallible; |
179 | 178 | //! |
180 | 179 | //! /// Encodes the u32 timestamp in big endian followed by the log level with a single byte. |
181 | | -//! fn to_bytes(log: &'a Self::SelfType) -> Result<Self::ReturnBytes, Self::Error> { |
| 180 | +//! fn bytes_encode(log: &Self::EItem) -> Result<Self::ReturnBytes, Self::Error> { |
182 | 181 | //! let mut output = [0; 5]; |
183 | 182 | //! |
184 | 183 | //! let [timestamp @ .., level] = &mut output; |
|
218 | 217 | //! /// the logs that appeared during a, rather long, period. |
219 | 218 | //! pub struct LogAtHalfTimestampCodec; |
220 | 219 | //! |
221 | | -//! impl<'a> ToBytes<'a> for LogAtHalfTimestampCodec { |
222 | | -//! type SelfType = u32; |
| 220 | +//! impl<'a> BytesEncode<'a> for LogAtHalfTimestampCodec { |
| 221 | +//! type EItem = u32; |
223 | 222 | //! |
224 | 223 | //! type ReturnBytes = [u8; 2]; |
225 | 224 | //! |
226 | 225 | //! type Error = Infallible; |
227 | 226 | //! |
228 | 227 | //! /// This method encodes only the prefix of the keys in this particular case, the timestamp. |
229 | | -//! fn to_bytes(half_timestamp: &'a Self::SelfType) -> Result<Self::ReturnBytes, Self::Error> { |
| 228 | +//! fn bytes_encode(half_timestamp: &Self::EItem) -> Result<Self::ReturnBytes, Self::Error> { |
230 | 229 | //! let [bytes @ .., _, _] = half_timestamp.to_be_bytes(); |
231 | 230 | //! Ok(bytes) |
232 | 231 | //! } |
|
457 | 456 | // To let cargo generate doc links |
458 | 457 | #![allow(unused_imports)] |
459 | 458 |
|
460 | | -use crate::{BytesDecode, Database, EnvOpenOptions, ToBytes}; |
| 459 | +use crate::{BytesDecode, BytesEncode, Database, EnvOpenOptions}; |
0 commit comments