generated from al8n/template-rs
-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
15 changed files
with
39 additions
and
970 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,29 @@ | ||
pub use dbutils::buffer::VacantBuffer; | ||
pub use dbutils::{buffer::VacantBuffer, builder}; | ||
|
||
macro_rules! builder { | ||
($($name:ident($size:ident)),+ $(,)?) => { | ||
macro_rules! builder_ext { | ||
($($name:ident),+ $(,)?) => { | ||
$( | ||
paste::paste! { | ||
#[doc = "A " [< $name: snake>] " builder for the wal, which requires the " [< $name: snake>] " size for accurate allocation and a closure to build the " [< $name: snake>]] | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct [< $name Builder >] <F> { | ||
size: $size, | ||
f: F, | ||
} | ||
|
||
impl<F> [< $name Builder >]<F> { | ||
#[doc = "Creates a new `" [<$name Builder>] "` with the given size and builder closure."] | ||
impl<F> $name<F> { | ||
#[doc = "Creates a new `" $name "` with the given size and builder closure which requires `FnOnce`."] | ||
#[inline] | ||
pub const fn once<E>(size: $size, f: F) -> Self | ||
pub const fn once<E>(size: u32, f: F) -> Self | ||
where | ||
F: for<'a> FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>, | ||
{ | ||
Self { size, f } | ||
} | ||
|
||
#[doc = "Creates a new `" [<$name Builder>] "` with the given size and builder closure."] | ||
#[inline] | ||
pub const fn new<E>(size: $size, f: F) -> Self | ||
where | ||
F: for<'a> Fn(&mut VacantBuffer<'a>) -> Result<(), E>, | ||
{ | ||
Self { size, f } | ||
} | ||
|
||
#[doc = "Returns the required" [< $name: snake>] "size."] | ||
#[inline] | ||
pub const fn size(&self) -> $size { | ||
self.size | ||
} | ||
|
||
#[doc = "Returns the " [< $name: snake>] "builder closure."] | ||
#[inline] | ||
pub const fn builder(&self) -> &F { | ||
&self.f | ||
} | ||
|
||
/// Deconstructs the value builder into the size and the builder closure. | ||
#[inline] | ||
pub fn into_components(self) -> ($size, F) { | ||
(self.size, self.f) | ||
} | ||
} | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
builder!(Value(u32), Key(u32)); | ||
builder!( | ||
/// A value builder for the wal, which requires the value size for accurate allocation and a closure to build the value. | ||
ValueBuilder(u32), | ||
/// A key builder for the wal, which requires the key size for accurate allocation and a closure to build the key. | ||
KeyBuilder(u32), | ||
); | ||
|
||
builder_ext!(ValueBuilder, KeyBuilder,); |
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
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
Oops, something went wrong.