-
Notifications
You must be signed in to change notification settings - Fork 9
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
11 changed files
with
226 additions
and
2 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,67 @@ | ||
use dyn_clone::DynClone; | ||
use dyn_hash::DynHash; | ||
use std::fmt::Debug; | ||
use std::sync::Arc; | ||
|
||
#[derive(Clone)] | ||
pub struct LazyEmbeddedDocument { | ||
bytes: Arc<Vec<u8>>, | ||
typ: DynEmbeddedTypeTag, | ||
} | ||
|
||
impl LazyEmbeddedDocument { | ||
pub fn new<B: Into<Vec<u8>>, T: Into<DynEmbeddedTypeTag>>(bytes: B, typ: T) -> Self { | ||
let bytes = Arc::new(bytes.into()); | ||
let typ = typ.into(); | ||
Self { bytes, typ } | ||
} | ||
} | ||
|
||
// dyn | ||
|
||
pub type DynEmbeddedTypeTag = Box<dyn DynEmbeddedDocumentType>; | ||
|
||
pub trait DynEmbeddedDocumentType: DynClone { | ||
fn construct(&self, bytes: &[u8]) -> Box<dyn EmbeddedDocument>; | ||
} | ||
|
||
dyn_clone::clone_trait_object!(DynEmbeddedDocumentType); | ||
|
||
pub trait DynEmbeddedDocumentTypeFactory { | ||
fn to_dyn_type_tag(self) -> DynEmbeddedTypeTag; | ||
} | ||
|
||
// typed | ||
|
||
pub type EmbeddedTypeTag<D> = Box<dyn EmbeddedDocumentType<Doc = D>>; | ||
pub trait EmbeddedDocumentType: Clone { | ||
type Doc: EmbeddedDocument + 'static; | ||
|
||
fn construct(&self, bytes: &[u8]) -> Self::Doc; | ||
} | ||
|
||
#[cfg_attr(feature = "serde", typetag::serde)] | ||
pub trait EmbeddedDocument: Debug + DynHash + DynClone {} | ||
|
||
dyn_hash::hash_trait_object!(EmbeddedDocument); | ||
dyn_clone::clone_trait_object!(EmbeddedDocument); | ||
|
||
impl<T, D> DynEmbeddedDocumentType for T | ||
where | ||
T: EmbeddedDocumentType<Doc = D>, | ||
D: EmbeddedDocument + 'static, | ||
{ | ||
fn construct(&self, bytes: &[u8]) -> Box<dyn EmbeddedDocument> { | ||
Box::new(EmbeddedDocumentType::construct(self, bytes)) | ||
} | ||
} | ||
|
||
impl<T, D> DynEmbeddedDocumentTypeFactory for T | ||
where | ||
T: EmbeddedDocumentType<Doc = D> + 'static, | ||
D: EmbeddedDocument + 'static, | ||
{ | ||
fn to_dyn_type_tag(self) -> DynEmbeddedTypeTag { | ||
Box::new(self) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,3 +8,5 @@ pub mod pretty; | |
pub mod syntax; | ||
|
||
pub mod catalog; | ||
|
||
pub mod embedded_document; |
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,76 @@ | ||
use partiql_common::embedded_document::{EmbeddedDocument, LazyEmbeddedDocument}; | ||
use partiql_common::pretty::{pretty_surrounded, pretty_surrounded_doc, PrettyDoc}; | ||
use pretty::{DocAllocator, DocBuilder}; | ||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
use std::fmt::{Debug, Formatter}; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
pub enum EmbeddedDoc { | ||
Lazy(LazyEmbeddedDocument), | ||
} | ||
|
||
impl Debug for EmbeddedDoc { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.write_str("<<TODO: Debug for EmbeddedDoc>>") | ||
} | ||
} | ||
|
||
impl Hash for EmbeddedDoc { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Clone for EmbeddedDoc { | ||
fn clone(&self) -> Self { | ||
match self { | ||
EmbeddedDoc::Lazy(doc) => Self::Lazy(doc.clone()), | ||
} | ||
} | ||
} | ||
|
||
impl PartialEq<Self> for EmbeddedDoc { | ||
fn eq(&self, other: &Self) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Eq for EmbeddedDoc {} | ||
|
||
#[cfg(feature = "serde")] | ||
impl Serialize for EmbeddedDoc { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
todo!() | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl<'de> Deserialize<'de> for EmbeddedDoc { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
todo!() | ||
} | ||
} | ||
|
||
impl PrettyDoc for EmbeddedDoc { | ||
fn pretty_doc<'b, D, A>(&'b self, arena: &'b D) -> DocBuilder<'b, D, A> | ||
where | ||
D: DocAllocator<'b, A>, | ||
D::Doc: Clone, | ||
A: Clone, | ||
{ | ||
todo!() | ||
/* | ||
//// TODO handle backticks better | ||
let doc = self.data.pretty_doc(arena); | ||
pretty_surrounded_doc(doc, "`````", "`````", arena) | ||
*/ | ||
} | ||
} |
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