-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
- Loading branch information
There are no files selected for viewing
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>>, | ||
Check warning on line 8 in partiql-common/src/embedded_document.rs
|
||
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>>; | ||
Check warning on line 36 in partiql-common/src/embedded_document.rs
|
||
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) | ||
} | ||
} |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use partiql_common::embedded_document::{EmbeddedDocument, LazyEmbeddedDocument}; | ||
Check warning on line 1 in partiql-value/src/embedded_doc.rs
|
||
use partiql_common::pretty::{pretty_surrounded, pretty_surrounded_doc, PrettyDoc}; | ||
Check warning on line 2 in partiql-value/src/embedded_doc.rs
|
||
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) { | ||
Check warning on line 20 in partiql-value/src/embedded_doc.rs
|
||
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 { | ||
Check warning on line 34 in partiql-value/src/embedded_doc.rs
|
||
todo!() | ||
} | ||
} | ||
|
||
impl Eq for EmbeddedDoc {} | ||
|
||
#[cfg(feature = "serde")] | ||
impl Serialize for EmbeddedDoc { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
Check warning on line 43 in partiql-value/src/embedded_doc.rs
|
||
where | ||
S: Serializer, | ||
{ | ||
todo!() | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl<'de> Deserialize<'de> for EmbeddedDoc { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
Check warning on line 53 in partiql-value/src/embedded_doc.rs
|
||
where | ||
D: Deserializer<'de>, | ||
{ | ||
todo!() | ||
} | ||
} | ||
|
||
impl PrettyDoc for EmbeddedDoc { | ||
fn pretty_doc<'b, D, A>(&'b self, arena: &'b D) -> DocBuilder<'b, D, A> | ||
Check warning on line 62 in partiql-value/src/embedded_doc.rs
|
||
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) | ||
*/ | ||
} | ||
} |