Skip to content

Commit

Permalink
feat: add AsRef and Deref for Document
Browse files Browse the repository at this point in the history
  • Loading branch information
fMeow committed Nov 15, 2020
1 parent d9ad511 commit 7f19ccf
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This mod contains document related types.
//! Operations are conducted on collection level struct
use serde::{Deserialize, Serialize};
use std::ops::Deref;

pub mod options;
pub mod response;
Expand All @@ -27,8 +28,8 @@ pub struct Document<T> {
}

impl<'de, T> Document<T>
where
T: Serialize + Deserialize<'de>,
where
T: Serialize + Deserialize<'de>,
{
pub fn new(data: T) -> Self {
Document {
Expand All @@ -41,3 +42,17 @@ where
}
}
}

impl<T> AsRef<T> for Document<T> {
fn as_ref(&self) -> &T {
&self.document
}
}

impl<T> Deref for Document<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.document
}
}

0 comments on commit 7f19ccf

Please sign in to comment.