-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces an application-level lazy writer
- Loading branch information
Showing
24 changed files
with
1,099 additions
and
308 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,106 @@ | ||
use crate::{RawSymbolTokenRef, SymbolId}; | ||
use smallvec::SmallVec; | ||
|
||
pub type AnnotationsVec<'a> = SmallVec<[RawSymbolTokenRef<'a>; 2]>; | ||
|
||
pub trait AnnotationSeq<'a> { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a>; | ||
} | ||
|
||
impl<'a> AnnotationSeq<'a> for &'a str { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut vec = AnnotationsVec::new(); | ||
vec.push(RawSymbolTokenRef::Text(self.into())); | ||
vec | ||
} | ||
} | ||
|
||
impl<'a> AnnotationSeq<'a> for &'a &str { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut vec = AnnotationsVec::new(); | ||
vec.push(RawSymbolTokenRef::Text((*self).into())); | ||
vec | ||
} | ||
} | ||
|
||
impl<'a> AnnotationSeq<'a> for SymbolId { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut vec = AnnotationsVec::new(); | ||
vec.push(RawSymbolTokenRef::SymbolId(self)); | ||
vec | ||
} | ||
} | ||
|
||
impl<'a> AnnotationSeq<'a> for &'a SymbolId { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut vec = AnnotationsVec::new(); | ||
vec.push(RawSymbolTokenRef::SymbolId(*self)); | ||
vec | ||
} | ||
} | ||
|
||
impl<'a> AnnotationSeq<'a> for RawSymbolTokenRef<'a> { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut vec = AnnotationsVec::new(); | ||
vec.push(self); | ||
vec | ||
} | ||
} | ||
|
||
impl<'a> AnnotationSeq<'a> for AnnotationsVec<'a> { | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
self | ||
} | ||
} | ||
|
||
impl<'a, T> AnnotationSeq<'a> for Vec<T> | ||
where | ||
T: Into<RawSymbolTokenRef<'a>>, | ||
{ | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut annotations = AnnotationsVec::new(); | ||
for token in self { | ||
annotations.push(token.into()); | ||
} | ||
annotations | ||
} | ||
} | ||
|
||
impl<'a, T> AnnotationSeq<'a> for &'a [T] | ||
where | ||
for<'b> &'b T: Into<RawSymbolTokenRef<'b>>, | ||
{ | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut annotations = AnnotationsVec::new(); | ||
for token in self { | ||
annotations.push(token.into()); | ||
} | ||
annotations | ||
} | ||
} | ||
|
||
impl<'a, T, const N: usize> AnnotationSeq<'a> for [T; N] | ||
where | ||
T: Into<RawSymbolTokenRef<'a>>, | ||
{ | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut annotations = AnnotationsVec::new(); | ||
for token in self { | ||
annotations.push(token.into()); | ||
} | ||
annotations | ||
} | ||
} | ||
|
||
impl<'a, T, const N: usize> AnnotationSeq<'a> for &'a [T; N] | ||
where | ||
for<'b> &'b T: Into<RawSymbolTokenRef<'b>>, | ||
{ | ||
fn into_annotations_vec(self) -> AnnotationsVec<'a> { | ||
let mut annotations = AnnotationsVec::new(); | ||
for token in self { | ||
annotations.push(token.into()); | ||
} | ||
annotations | ||
} | ||
} |
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,12 +1,21 @@ | ||
use crate::lazy::encoder::binary::v1_0::writer::LazyRawBinaryWriter_1_0; | ||
use crate::lazy::encoder::LazyEncoder; | ||
use crate::lazy::encoder::{LazyEncoder, SymbolCreationPolicy}; | ||
use crate::lazy::encoding::BinaryEncoding_1_0; | ||
use crate::WriteConfig; | ||
use std::io::Write; | ||
|
||
mod container_writers; | ||
pub mod value_writer; | ||
pub mod writer; | ||
|
||
impl LazyEncoder for BinaryEncoding_1_0 { | ||
const SUPPORTS_TEXT_TOKENS: bool = false; | ||
const DEFAULT_SYMBOL_CREATION_POLICY: SymbolCreationPolicy = | ||
SymbolCreationPolicy::RequireSymbolId; | ||
|
||
type Writer<W: Write> = LazyRawBinaryWriter_1_0<W>; | ||
|
||
fn default_write_config() -> WriteConfig<Self> { | ||
WriteConfig::<Self>::new() | ||
} | ||
} |
Oops, something went wrong.