Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove entry newtype #6

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 7 additions & 52 deletions src/rpc/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use quic_rpc::{client::BoxedConnector, message::RpcMsg, Connector};
use serde::{Deserialize, Serialize};

use super::flatten;
#[doc(inline)]
pub use crate::engine::{LiveEvent, Origin, SyncEvent, SyncReason};
use crate::{
actor::OpenState,
rpc::proto::{
Expand All @@ -32,7 +30,12 @@ use crate::{
StartSyncRequest, StatusRequest,
},
store::{DownloadPolicy, Query},
AuthorId, Capability, CapabilityKind, DocTicket, NamespaceId, PeerIdBytes, RecordIdentifier,
AuthorId, Capability, CapabilityKind, DocTicket, NamespaceId, PeerIdBytes,
};
#[doc(inline)]
pub use crate::{
engine::{LiveEvent, Origin, SyncEvent, SyncReason},
Entry,
};

/// Iroh docs client.
Expand Down Expand Up @@ -265,7 +268,7 @@ impl<C: Connector<RpcService>> Doc<C> {
.0
.rpc
.server_streaming(ExportFileRequest {
entry: entry.0,
entry,
path: path.as_ref().into(),
mode,
})
Expand Down Expand Up @@ -428,54 +431,6 @@ where
}
}

/// A single entry in a [`Doc`].
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct Entry(crate::Entry);

impl From<crate::Entry> for Entry {
fn from(value: crate::Entry) -> Self {
Self(value)
}
}

impl From<crate::SignedEntry> for Entry {
fn from(value: crate::SignedEntry) -> Self {
Self(value.into())
}
}

impl Entry {
/// Returns the [`RecordIdentifier`] for this entry.
pub fn id(&self) -> &RecordIdentifier {
self.0.id()
}

/// Returns the [`AuthorId`] of this entry.
pub fn author(&self) -> AuthorId {
self.0.author()
}

/// Returns the [`struct@Hash`] of the content data of this record.
pub fn content_hash(&self) -> Hash {
self.0.content_hash()
}

/// Returns the length of the data addressed by this record's content hash.
pub fn content_len(&self) -> u64 {
self.0.content_len()
}

/// Returns the key of this entry.
pub fn key(&self) -> &[u8] {
self.0.key()
}

/// Returns the timestamp of this entry.
pub fn timestamp(&self) -> u64 {
self.0.timestamp()
}
}

/// Progress messages for an doc import operation
///
/// An import operation involves computing the outboard of a file, and then
Expand Down
15 changes: 15 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,21 @@ impl Entry {
&self.record
}

/// Get the content hash of the record.
pub fn content_hash(&self) -> Hash {
self.record.hash
}

/// Get the content length of the record.
pub fn content_len(&self) -> u64 {
self.record.len
}

/// Get the timestamp of the record.
pub fn timestamp(&self) -> u64 {
self.record.timestamp
}

/// Serialize this entry into its canonical byte representation used for signing.
pub fn encode(&self, out: &mut Vec<u8>) {
self.id.encode(out);
Expand Down
Loading