pub struct Entry { /* private fields */ }Expand description
One entry of a folder: a name, the file or folder under it, and extra data.
Implementations§
Source§impl Entry
impl Entry
Sourcepub fn new(
name: impl Into<String>,
target: Target,
extra: ExtraData,
) -> Result<Self>
pub fn new( name: impl Into<String>, target: Target, extra: ExtraData, ) -> Result<Self>
Examples found in repository?
examples/proof_sizes.rs (line 43)
32fn main() -> Result<()> {
33 println!("One entry of a folder, by its name. Names are 16 bytes long.");
34 println!(
35 "{:>10} {:>12} {:>8} {:>10}",
36 "entries", "whole list", "branch", "smaller by"
37 );
38 for count in [10_usize, 1_000, 10_000, 1_000_000] {
39 let store = MemoryStore::new();
40 let mut builder = Builder::new(&store, Chunking::fixed(16)?);
41 let file = builder.file_from_bytes(b"the same small file")?;
42 let entries = (0..count)
43 .map(|number| Entry::new(format!("file-{number:07}.bin"), file, ExtraData::new()))
44 .collect::<Result<Vec<_>>>()?;
45 let folder = builder.folder(entries)?;
46 let list = store
47 .get(Stored::FolderList, &folder.hash)?
48 .map_or(0, |list| list.len());
49 let request = Request::FolderName {
50 folder: folder.hash,
51 name: format!("file-{:07}.bin", count / 2),
52 };
53 row(count, list, answer_bytes(&store, &request)?);
54 }
55
56 println!();
57 println!("One chunk of a file, by its number.");
58 println!(
59 "{:>10} {:>12} {:>8} {:>10}",
60 "chunks", "whole list", "branch", "smaller by"
61 );
62 for count in [10_usize, 1_000, 10_000, 500_000] {
63 // Chunks of one byte, so that a file of many chunks is small.
64 let store = MemoryStore::new();
65 let mut builder = Builder::new(&store, Chunking::fixed(1)?);
66 let bytes: Vec<u8> = (0..count).map(|at| (at % 251) as u8).collect();
67 let file = builder.file_from_bytes(&bytes)?;
68 let list = store
69 .get(Stored::FileList, &file.hash)?
70 .map_or(0, |list| list.len());
71 let request = Request::FileBranch {
72 file: file.hash,
73 start: (count / 2) as u64,
74 count: 1,
75 };
76 row(count, list, answer_bytes(&store, &request)?);
77 }
78 Ok(())
79}pub fn name(&self) -> &str
pub fn kind(&self) -> Kind
pub fn hash(&self) -> &Hash
Sourcepub fn target(&self) -> Target
pub fn target(&self) -> Target
The file or folder under this entry.
Examples found in repository?
examples/roundtrip.rs (line 206)
194fn largest_file(store: &dyn Store, top: Target) -> Result<Option<Target>> {
195 let mut largest: Option<Target> = None;
196 let mut seen = std::collections::HashSet::new();
197 let mut pending = vec![top];
198 while let Some(target) = pending.pop() {
199 match target.kind {
200 Kind::File if largest.is_none_or(|file| file.size < target.size) => {
201 largest = Some(target);
202 }
203 Kind::File => {}
204 Kind::Folder if seen.insert(target.hash) => {
205 let list = folder_of(store, &target)?;
206 pending.extend(list.entries().iter().map(|entry| entry.target()));
207 }
208 Kind::Folder => {}
209 }
210 }
211 Ok(largest)
212}pub fn extra(&self) -> &ExtraData
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
How many bytes the entry takes in its folder’s list.
Trait Implementations§
impl Eq for Entry
impl StructuralPartialEq for Entry
Auto Trait Implementations§
impl Forget for Entry
impl Freeze for Entry
impl Move for Entry
impl RefUnwindSafe for Entry
impl Send for Entry
impl Sync for Entry
impl Unpin for Entry
impl UnsafeUnpin for Entry
impl UnwindSafe for Entry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more