-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2960403
commit f74630e
Showing
5 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::{error::Result, Cell}; | ||
use std::io::Read; | ||
|
||
/// The `Deserializer` trait defines the contract for reading concrete types | ||
/// from a disk tree. | ||
pub trait Deserializer<R> { | ||
/// The associated type `T` represents the result of deserialization, | ||
/// which may be the deserialized type or an error result, depending on fallibility. | ||
type T; | ||
|
||
/// Reads data from the provided reader and returns the deserialized result. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `rdr` - A `Result` containing a `Cell` and a mutable reference to the reader. | ||
/// | ||
/// # Returns | ||
/// | ||
/// The deserialized result, which can be the deserialized type or an error. | ||
fn read(&self, rdr: Result<(Cell, &mut R)>) -> Self::T; | ||
} | ||
|
||
impl<R, T, F> Deserializer<R> for F | ||
where | ||
R: Read, | ||
F: Fn(Result<(Cell, &mut R)>) -> T, | ||
{ | ||
type T = T; | ||
|
||
fn read(&self, rdr: Result<(Cell, &mut R)>) -> T { | ||
self(rdr) | ||
} | ||
} |