diff --git a/README.md b/README.md index 455a5775..794cad0b 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ use wnfs::{ #[async_std::main] async fn main() -> Result<()> { // Create a new public directory. - let dir = &mut PublicDirectory::rc(Utc::now()); + let dir = &mut PublicDirectory::new_rc(Utc::now()); // Create an in-memory block store. let store = &MemoryBlockStore::default(); @@ -233,10 +233,10 @@ async fn main() -> Result<()> { let rng = &mut thread_rng(); // Create a private forest. - let forest = &mut HamtForest::rc_trusted(rng); + let forest = &mut HamtForest::new_trusted_rc(rng); // Create a new private directory. - let dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); // Add a file to /pictures/cats directory. dir.mkdir( diff --git a/wnfs/README.md b/wnfs/README.md index dcaee165..1719094b 100644 --- a/wnfs/README.md +++ b/wnfs/README.md @@ -54,7 +54,7 @@ use wnfs::{ #[async_std::main] async fn main() -> Result<()> { // Create a new public directory. - let dir = &mut PublicDirectory::rc(Utc::now()); + let dir = &mut PublicDirectory::new_rc(Utc::now()); // Create an in-memory block store. let store = &MemoryBlockStore::default(); @@ -102,10 +102,10 @@ async fn main() -> Result<()> { let rng = &mut thread_rng(); // Create a private forest. - let forest = &mut HamtForest::rc_trusted(rng); + let forest = &mut HamtForest::new_trusted_rc(rng); // Create a new private directory. - let dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); // Add a file to /pictures/cats directory. dir.mkdir( diff --git a/wnfs/examples/file_variants.rs b/wnfs/examples/file_variants.rs index ece4dd6c..f341f9ac 100644 --- a/wnfs/examples/file_variants.rs +++ b/wnfs/examples/file_variants.rs @@ -4,7 +4,6 @@ use anyhow::Result; use chrono::Utc; use rand::thread_rng; -use std::rc::Rc; use wnfs::private::{ forest::{hamt::HamtForest, traits::PrivateForest}, PrivateFile, PrivateForestContent, @@ -19,17 +18,15 @@ async fn main() -> Result<()> { let forest = &mut HamtForest::new_rsa_2048(rng); // Create a new file (detached from any directory) - let mut file = Rc::new( - PrivateFile::with_content( - &forest.empty_name(), - Utc::now(), - b"main content".to_vec(), - forest, - store, - rng, - ) - .await?, - ); + let mut file = PrivateFile::with_content_rc( + &forest.empty_name(), + Utc::now(), + b"main content".to_vec(), + forest, + store, + rng, + ) + .await?; // Create some content that's stored encrypted in the private forest. // The PrivateForestContent struct holds the keys and pointers to look it back up. diff --git a/wnfs/examples/mnemonic_based.rs b/wnfs/examples/mnemonic_based.rs index 914167c3..66b7af08 100644 --- a/wnfs/examples/mnemonic_based.rs +++ b/wnfs/examples/mnemonic_based.rs @@ -57,7 +57,7 @@ async fn main() -> Result<()> { async fn root_dir_setup(store: &impl BlockStore) -> Result<(Rc, AccessKey)> { // We generate a new simple example file system: let rng = &mut rand::thread_rng(); - let forest = &mut HamtForest::rc_trusted(rng); + let forest = &mut HamtForest::new_trusted_rc(rng); let root_dir = &mut PrivateDirectory::new_and_store(&forest.empty_name(), Utc::now(), forest, store, rng) .await?; @@ -93,7 +93,7 @@ async fn setup_seeded_keypair_access( // Store the public key inside some public WNFS. // Building from scratch in this case. Would actually be stored next to the private forest usually. let public_key_cid = exchange_keypair.store_public_key(store).await?; - let mut exchange_root = PublicDirectory::rc(Utc::now()); + let mut exchange_root = PublicDirectory::new_rc(Utc::now()); exchange_root .write( &["main".into(), "v1.exchange_key".into()], diff --git a/wnfs/examples/private.rs b/wnfs/examples/private.rs index dcc6a485..d142f6ae 100644 --- a/wnfs/examples/private.rs +++ b/wnfs/examples/private.rs @@ -46,10 +46,10 @@ async fn create_forest_and_add_directory( let setup = AccumulatorSetup::trusted(rng); // Create the private forest (a HAMT), a map-like structure where file and directory ciphertexts are stored. - let forest = &mut HamtForest::rc(setup); + let forest = &mut HamtForest::new_rc(setup); // Create a new directory. - let dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); // Add a /pictures/cats subdirectory. dir.mkdir( diff --git a/wnfs/examples/public.rs b/wnfs/examples/public.rs index 6e92fb65..c13d3c54 100644 --- a/wnfs/examples/public.rs +++ b/wnfs/examples/public.rs @@ -12,7 +12,7 @@ async fn main() -> Result<()> { let store = MemoryBlockStore::default(); // Create a new directory. - let root_dir = &mut PublicDirectory::rc(Utc::now()); + let root_dir = &mut PublicDirectory::new_rc(Utc::now()); // Add a /pictures/cats subdirectory. root_dir diff --git a/wnfs/examples/tiered_blockstores.rs b/wnfs/examples/tiered_blockstores.rs index 2bd2adf5..000efc66 100644 --- a/wnfs/examples/tiered_blockstores.rs +++ b/wnfs/examples/tiered_blockstores.rs @@ -32,10 +32,10 @@ async fn main() -> Result<()> { // Create a new private forest. // This represents your whole private file system, but hides any internal structure. - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); // Create a new private directory - let mut directory = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let mut directory = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let file_path = ["datasets".into(), "recordings".into(), "monday.mp4".into()]; let video = b"This isn't actually a video. But it could be!"; diff --git a/wnfs/examples/write_proofs.rs b/wnfs/examples/write_proofs.rs index 3ae60727..8ea0f4d9 100644 --- a/wnfs/examples/write_proofs.rs +++ b/wnfs/examples/write_proofs.rs @@ -54,8 +54,8 @@ async fn main() -> Result<()> { /// supposed to be publicly signed for verifyable write access. async fn alice_actions(store: &impl BlockStore) -> Result<(Cid, AccessKey, NameAccumulator)> { let rng = &mut thread_rng(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let access_key = root_dir.as_node().store(forest, store, rng).await?; let cid = forest.store(store).await?; diff --git a/wnfs/src/lib.rs b/wnfs/src/lib.rs index 0d38d4b7..a1bfc65e 100644 --- a/wnfs/src/lib.rs +++ b/wnfs/src/lib.rs @@ -19,7 +19,7 @@ //! #[async_std::main] //! async fn main() -> Result<()> { //! // Create a new public directory. -//! let dir = &mut PublicDirectory::rc(Utc::now()); +//! let dir = &mut PublicDirectory::new_rc(Utc::now()); //! //! // Create an in-memory block store. //! let store = &MemoryBlockStore::default(); @@ -67,10 +67,10 @@ //! let rng = &mut thread_rng(); //! //! // Create a private forest. -//! let forest = &mut HamtForest::rc_trusted(rng); +//! let forest = &mut HamtForest::new_trusted_rc(rng); //! //! // Create a new private directory. -//! let dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); +//! let dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); //! //! // Add a file to /pictures/cats directory. //! dir.mkdir( diff --git a/wnfs/src/private/directory.rs b/wnfs/src/private/directory.rs index def88011..2e7d663c 100644 --- a/wnfs/src/private/directory.rs +++ b/wnfs/src/private/directory.rs @@ -104,11 +104,15 @@ impl PrivateDirectory { /// /// let rng = &mut thread_rng(); /// let forest = HamtForest::new_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// println!("dir = {:?}", dir); /// ``` - pub fn rc(parent_name: &Name, time: DateTime, rng: &mut impl CryptoRngCore) -> Rc { + pub fn new_rc( + parent_name: &Name, + time: DateTime, + rng: &mut impl CryptoRngCore, + ) -> Rc { Rc::new(Self::new(parent_name, time, rng)) } @@ -188,7 +192,7 @@ impl PrivateDirectory { /// let rng = &mut thread_rng(); /// let forest = &mut HamtForest::new_rsa_2048(rng); /// let time = Utc::now(); - /// let dir = PrivateDirectory::rc( + /// let dir = PrivateDirectory::new_rc( /// &forest.empty_name(), /// time, /// rng, @@ -218,8 +222,8 @@ impl PrivateDirectory { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .mkdir(&["pictures".into(), "cats".into()], true, Utc::now(), forest, store, rng) @@ -447,8 +451,8 @@ impl PrivateDirectory { /// async fn main() { /// let store = &MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .mkdir(&["pictures".into(), "cats".into()], true, Utc::now(), forest, store, rng) @@ -501,8 +505,8 @@ impl PrivateDirectory { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// let content = b"print('hello world')"; /// @@ -572,8 +576,8 @@ impl PrivateDirectory { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// // The path to the file /code/hello.py as defined by our standards /// let hello_py: &[String] = &["code".into(), "hello.py".into()]; /// // The original file content @@ -656,8 +660,8 @@ impl PrivateDirectory { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// let content = b"print('hello world')"; /// @@ -744,7 +748,7 @@ impl PrivateDirectory { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// let mut init_dir = PrivateDirectory::new_and_store( /// &forest.empty_name(), /// Utc::now(), @@ -803,8 +807,8 @@ impl PrivateDirectory { /// async fn main() { /// let store = &MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .mkdir(&["pictures".into(), "cats".into()], true, Utc::now(), forest, store, rng) @@ -851,8 +855,8 @@ impl PrivateDirectory { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .write( @@ -941,8 +945,8 @@ impl PrivateDirectory { /// async fn main() { /// let store = &MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .write( @@ -1061,8 +1065,8 @@ impl PrivateDirectory { /// async fn main() { /// let store = &MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .write( @@ -1146,8 +1150,8 @@ impl PrivateDirectory { /// async fn main() { /// let store = &MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// root_dir /// .write( @@ -1399,8 +1403,8 @@ mod tests { async fn look_up_can_fetch_file_added_to_directory() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let content = b"Hello, World!".to_vec(); @@ -1429,8 +1433,8 @@ mod tests { async fn look_up_cannot_fetch_file_not_added_to_directory() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &HamtForest::rc_rsa_2048(rng); - let root_dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &HamtForest::new_rsa_2048_rc(rng); + let root_dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let node = root_dir .lookup_node("Unknown", true, forest, store) @@ -1444,8 +1448,8 @@ mod tests { async fn get_node_can_fetch_node_from_root_dir() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .mkdir( @@ -1521,8 +1525,8 @@ mod tests { async fn mkdir_can_create_new_directory() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .mkdir( @@ -1548,8 +1552,8 @@ mod tests { async fn ls_can_list_children_under_directory() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .mkdir( @@ -1602,8 +1606,8 @@ mod tests { async fn rm_can_remove_children_from_directory() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .mkdir( @@ -1658,8 +1662,8 @@ mod tests { async fn read_can_fetch_userland_of_file_added_to_directory() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .write( @@ -1686,8 +1690,8 @@ mod tests { async fn search_latest_finds_the_most_recent() { let rng = &mut rand::thread_rng(); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let path = ["Documents".into(), "file.txt".into()]; @@ -1735,8 +1739,8 @@ mod tests { async fn cp_can_copy_sub_directory_to_another_valid_location_with_updated_ancestry() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .write( @@ -1831,8 +1835,8 @@ mod tests { async fn mv_can_move_sub_directory_to_another_valid_location_with_updated_ancestry() { let rng = &mut thread_rng(); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .write( @@ -1926,8 +1930,8 @@ mod tests { async fn mv_cannot_move_sub_directory_to_invalid_location() { let rng = &mut thread_rng(); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .mkdir( @@ -1965,8 +1969,8 @@ mod tests { async fn mv_can_rename_directories() { let rng = &mut thread_rng(); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let content = b"file".to_vec(); root_dir @@ -2014,8 +2018,8 @@ mod tests { async fn mv_fails_moving_directories_to_files() { let rng = &mut thread_rng(); let store = &MemoryBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); root_dir .mkdir( @@ -2061,8 +2065,8 @@ mod tests { async fn write_doesnt_generate_previous_link() { let rng = &mut thread_rng(); let store = &MemoryBlockStore::new(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let old_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let old_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let new_dir = &mut Rc::clone(old_dir); new_dir @@ -2086,8 +2090,8 @@ mod tests { async fn store_before_write_generates_previous_link() { let rng = &mut thread_rng(); let store = &MemoryBlockStore::new(); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let old_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let old_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); old_dir.store(forest, store, rng).await.unwrap(); let new_dir = &mut Rc::clone(old_dir); @@ -2226,7 +2230,7 @@ mod snapshot_tests { async fn test_private_fs() -> Result<()> { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &mut SnapshotBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); let base_name = forest.empty_name(); let paths = [ @@ -2235,7 +2239,7 @@ mod snapshot_tests { vec!["videos".into(), "movies".into(), "anime".into()], ]; - let root_dir = &mut PrivateDirectory::rc(&base_name, time, rng); + let root_dir = &mut PrivateDirectory::new_rc(&base_name, time, rng); for path in paths.iter() { root_dir diff --git a/wnfs/src/private/file.rs b/wnfs/src/private/file.rs index 715a55ca..606bc5f1 100644 --- a/wnfs/src/private/file.rs +++ b/wnfs/src/private/file.rs @@ -54,7 +54,7 @@ pub const MAX_BLOCK_CONTENT_SIZE: usize = MAX_BLOCK_SIZE - NONCE_SIZE - AUTHENTI /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); -/// let forest = &mut HamtForest::rc_rsa_2048(rng); +/// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let file = PrivateFile::with_content( /// &forest.empty_name(), @@ -157,11 +157,15 @@ impl PrivateFile { /// /// let rng = &mut thread_rng(); /// let forest = HamtForest::new_rsa_2048(rng); - /// let file = PrivateFile::rc(&forest.empty_name(), Utc::now(), rng); + /// let file = PrivateFile::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// println!("file = {:?}", file); /// ``` - pub fn rc(parent_name: &Name, time: DateTime, rng: &mut impl CryptoRngCore) -> Rc { + pub fn new_rc( + parent_name: &Name, + time: DateTime, + rng: &mut impl CryptoRngCore, + ) -> Rc { Rc::new(Self::new(parent_name, time, rng)) } @@ -181,7 +185,7 @@ impl PrivateFile { /// async fn main() { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let file = PrivateFile::with_content( /// &forest.empty_name(), @@ -235,9 +239,9 @@ impl PrivateFile { /// async fn main() { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// - /// let file = PrivateFile::rc_with_content( + /// let file = PrivateFile::with_content_rc( /// &forest.empty_name(), /// Utc::now(), /// get_random_bytes::<100>(rng).to_vec(), @@ -251,7 +255,7 @@ impl PrivateFile { /// println!("file = {:?}", file); /// } /// ``` - pub async fn rc_with_content( + pub async fn with_content_rc( parent_name: &Name, time: DateTime, content: Vec, @@ -287,7 +291,7 @@ impl PrivateFile { /// /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let file = PrivateFile::with_content_streaming( /// &forest.empty_name(), @@ -347,9 +351,9 @@ impl PrivateFile { /// /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// - /// let file = PrivateFile::rc_with_content_streaming( + /// let file = PrivateFile::with_content_streaming_rc( /// &forest.empty_name(), /// Utc::now(), /// disk_file, @@ -364,7 +368,7 @@ impl PrivateFile { /// Ok(()) /// } /// ``` - pub async fn rc_with_content_streaming( + pub async fn with_content_streaming_rc( parent_name: &Name, time: DateTime, content: impl AsyncRead + Unpin, @@ -396,7 +400,7 @@ impl PrivateFile { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let file = PrivateFile::with_content( /// &forest.empty_name(), @@ -408,7 +412,7 @@ impl PrivateFile { /// ) /// .await?; /// - /// let root_dir = &mut PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let root_dir = &mut PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// let copy = root_dir /// .open_file_mut(&["some".into(), "copy.txt".into()], true, Utc::now(), forest, store, rng) @@ -444,7 +448,7 @@ impl PrivateFile { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let content = get_random_bytes::<100>(rng).to_vec(); /// let file = PrivateFile::with_content( @@ -534,7 +538,7 @@ impl PrivateFile { /// async fn main() -> Result<()> { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let content = get_random_bytes::<100>(rng).to_vec(); /// let file = PrivateFile::with_content( @@ -1070,7 +1074,7 @@ mod tests { async fn can_create_empty_file() { let store = &MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &HamtForest::rc_rsa_2048(rng); + let forest = &HamtForest::new_rsa_2048_rc(rng); let file = PrivateFile::new(&forest.empty_name(), Utc::now(), rng); let file_content = file.get_content(forest, store).await.unwrap(); @@ -1085,7 +1089,7 @@ mod tests { let store = &MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let file = PrivateFile::with_content( &forest.empty_name(), @@ -1126,7 +1130,7 @@ mod tests { let store = &MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let file = PrivateFile::with_content_streaming( &forest.empty_name(), @@ -1171,7 +1175,7 @@ mod proptests { let content = vec![0u8; length]; let store = &MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let file = PrivateFile::with_content( &forest.empty_name(), @@ -1198,7 +1202,7 @@ mod proptests { let content = vec![0u8; length]; let store = &MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let file = PrivateFile::with_content( &forest.empty_name(), @@ -1230,7 +1234,7 @@ mod proptests { async_std::task::block_on(async { let store = &MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let mut file = PrivateFile::new(&forest.empty_name(), Utc::now(), rng); @@ -1270,7 +1274,7 @@ mod proptests { .unwrap(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let store = &MemoryBlockStore::new(); let file = PrivateFile::with_content_streaming( diff --git a/wnfs/src/private/forest/hamt.rs b/wnfs/src/private/forest/hamt.rs index 603bf1c1..df80b09f 100644 --- a/wnfs/src/private/forest/hamt.rs +++ b/wnfs/src/private/forest/hamt.rs @@ -61,7 +61,7 @@ impl HamtForest { } /// Create a new, empty hamt forest with given pre-run accumulator setup wrapped in an `Rc`. - pub fn rc(setup: AccumulatorSetup) -> Rc { + pub fn new_rc(setup: AccumulatorSetup) -> Rc { Rc::new(Self::new(setup)) } @@ -77,7 +77,7 @@ impl HamtForest { /// Creates an `Rc` of a new, empty hamt forest with an accumulator setup /// based on the factors of the RSA-2048 factoring challenge modulus. - pub fn rc_rsa_2048(rng: &mut impl CryptoRngCore) -> Rc { + pub fn new_rsa_2048_rc(rng: &mut impl CryptoRngCore) -> Rc { Rc::new(Self::new_rsa_2048(rng)) } @@ -100,7 +100,7 @@ impl HamtForest { /// Creates an `Rc` of a new, empty hamt forest with a trusted accumulator /// setup. - pub fn rc_trusted(rng: &mut impl CryptoRngCore) -> Rc { + pub fn new_trusted_rc(rng: &mut impl CryptoRngCore) -> Rc { Rc::new(Self::new_trusted(rng)) } @@ -297,7 +297,7 @@ impl HamtForest { /// let store = &mut MemoryBlockStore::new(); /// let rng = &mut thread_rng(); /// - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// let root_dir = &mut PrivateDirectory::new_and_store( /// &forest.empty_name(), /// Utc::now(), @@ -439,7 +439,7 @@ mod tests { async fn test_put_get() { let store = &mut MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let cid = Cid::default(); let name = forest.empty_name().with_segments_added([ @@ -457,8 +457,8 @@ mod tests { async fn inserted_items_can_be_fetched() { let store = &mut MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let private_node = PrivateNode::Dir(dir.clone()); let private_ref = private_node.store(forest, store, rng).await.unwrap(); @@ -473,8 +473,8 @@ mod tests { async fn multivalue_conflict_can_be_fetched_individually() { let store = &mut MemoryBlockStore::new(); let rng = &mut ChaCha12Rng::seed_from_u64(0); - let forest = &mut HamtForest::rc_rsa_2048(rng); - let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); + let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); let dir_conflict = { let mut dir = (*dir).clone(); @@ -540,7 +540,7 @@ mod snapshot_tests { async fn test_hamt() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &SnapshotBlockStore::default(); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let base_name = forest.empty_name(); let name_segments = [ vec![NameSegment::new(rng)], diff --git a/wnfs/src/private/forest/traits.rs b/wnfs/src/private/forest/traits.rs index c4f79148..433bf457 100644 --- a/wnfs/src/private/forest/traits.rs +++ b/wnfs/src/private/forest/traits.rs @@ -74,8 +74,8 @@ pub trait PrivateForest { /// async fn main() { /// let store = &mut MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::Dir(dir); /// let access_key = node.store(forest, store, rng).await.unwrap(); /// diff --git a/wnfs/src/private/node/header.rs b/wnfs/src/private/node/header.rs index f3142d49..34a53917 100644 --- a/wnfs/src/private/node/header.rs +++ b/wnfs/src/private/node/header.rs @@ -136,7 +136,7 @@ impl PrivateNodeHeader { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// let file = PrivateFile::new(&forest.empty_name(), Utc::now(), rng); /// let revision_name = file.header.get_revision_name(); /// diff --git a/wnfs/src/private/node/node.rs b/wnfs/src/private/node/node.rs index ced8aea4..5a1d9fa2 100644 --- a/wnfs/src/private/node/node.rs +++ b/wnfs/src/private/node/node.rs @@ -37,8 +37,8 @@ use wnfs_nameaccumulator::Name; /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); -/// let forest = &mut HamtForest::rc_rsa_2048(rng); -/// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); +/// let forest = &mut HamtForest::new_rsa_2048_rc(rng); +/// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::Dir(dir); /// /// println!("Node: {:?}", node); @@ -69,8 +69,8 @@ impl PrivateNode { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::Dir(dir); /// /// let time = Utc::now() + Duration::days(1); @@ -149,8 +149,8 @@ impl PrivateNode { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::Dir(Rc::clone(&dir)); /// /// assert_eq!(&dir.header, node.get_header()); @@ -204,8 +204,8 @@ impl PrivateNode { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::Dir(Rc::clone(&dir)); /// /// assert_eq!(node.as_dir().unwrap(), dir); @@ -241,8 +241,8 @@ impl PrivateNode { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let file = PrivateFile::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let file = PrivateFile::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::File(Rc::clone(&file)); /// /// assert_eq!(node.as_file().unwrap(), file); @@ -269,8 +269,8 @@ impl PrivateNode { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::Dir(dir); /// /// assert!(node.is_dir()); @@ -294,8 +294,8 @@ impl PrivateNode { /// use rand::thread_rng; /// /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let file = PrivateFile::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let file = PrivateFile::new_rc(&forest.empty_name(), Utc::now(), rng); /// let node = PrivateNode::File(file); /// /// assert!(node.is_file()); @@ -324,7 +324,7 @@ impl PrivateNode { /// async fn main() { /// let store = &MemoryBlockStore::default(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); /// /// let mut init_dir = PrivateDirectory::new_and_store( /// &forest.empty_name(), @@ -538,8 +538,8 @@ impl PrivateNode { /// async fn main() { /// let store = &MemoryBlockStore::new(); /// let rng = &mut thread_rng(); - /// let forest = &mut HamtForest::rc_rsa_2048(rng); - /// let dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + /// let forest = &mut HamtForest::new_rsa_2048_rc(rng); + /// let dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); /// /// let node = PrivateNode::Dir(dir); /// @@ -610,7 +610,7 @@ mod tests { async fn serialized_private_node_can_be_deserialized() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let content = b"Lorem ipsum dolor sit amet"; - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let store = &MemoryBlockStore::new(); let file = PrivateFile::with_content( &forest.empty_name(), @@ -622,7 +622,7 @@ mod tests { ) .await .unwrap(); - let mut directory = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), rng); + let mut directory = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), rng); directory .mkdir(&["music".into()], true, Utc::now(), forest, store, rng) diff --git a/wnfs/src/private/previous.rs b/wnfs/src/private/previous.rs index cc54af56..d252d2f1 100644 --- a/wnfs/src/private/previous.rs +++ b/wnfs/src/private/previous.rs @@ -516,7 +516,7 @@ mod tests { let mut rng = ChaCha12Rng::seed_from_u64(0); let store = MemoryBlockStore::default(); let forest = Rc::new(HamtForest::new_rsa_2048(&mut rng)); - let root_dir = PrivateDirectory::rc(&forest.empty_name(), Utc::now(), &mut rng); + let root_dir = PrivateDirectory::new_rc(&forest.empty_name(), Utc::now(), &mut rng); Self { rng, diff --git a/wnfs/src/private/share.rs b/wnfs/src/private/share.rs index bc571edf..98f7d884 100644 --- a/wnfs/src/private/share.rs +++ b/wnfs/src/private/share.rs @@ -248,7 +248,7 @@ mod tests { let exchange_key = key.get_public_key().get_public_key_modulus()?; let exchange_key_cid = store.put_block(exchange_key, CODEC_RAW).await?; - let mut root_dir = PublicDirectory::rc(Utc::now()); + let mut root_dir = PublicDirectory::new_rc(Utc::now()); root_dir .write( &["device1".into(), EXCHANGE_KEY_NAME.into()], @@ -266,7 +266,7 @@ mod tests { async fn can_share_and_recieve_share() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::new(); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let sharer_root_did = "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"; @@ -320,7 +320,7 @@ mod tests { async fn serialized_share_payload_can_be_deserialized() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::new(); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let dir = PrivateDirectory::new_and_store(&forest.empty_name(), Utc::now(), forest, store, rng) .await @@ -342,7 +342,7 @@ mod tests { async fn find_latest_share_counter_finds_highest_count() { let rng = &mut ChaCha12Rng::seed_from_u64(0); let store = &MemoryBlockStore::new(); - let forest = &mut HamtForest::rc_rsa_2048(rng); + let forest = &mut HamtForest::new_rsa_2048_rc(rng); let sharer_root_did = "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"; diff --git a/wnfs/src/public/directory.rs b/wnfs/src/public/directory.rs index 8358d877..61ddb2a3 100644 --- a/wnfs/src/public/directory.rs +++ b/wnfs/src/public/directory.rs @@ -79,11 +79,11 @@ impl PublicDirectory { /// use wnfs::public::PublicDirectory; /// use chrono::Utc; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// /// println!("Directory: {:?}", dir); /// ``` - pub fn rc(time: DateTime) -> Rc { + pub fn new_rc(time: DateTime) -> Rc { Rc::new(Self::new(time)) } @@ -96,7 +96,7 @@ impl PublicDirectory { /// use std::{rc::Rc, collections::BTreeSet}; /// use chrono::Utc; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// /// assert_eq!(dir.get_previous(), &BTreeSet::new()); /// ``` @@ -114,7 +114,7 @@ impl PublicDirectory { /// use chrono::Utc; /// /// let time = Utc::now(); - /// let dir = PublicDirectory::rc(time); + /// let dir = PublicDirectory::new_rc(time); /// /// assert_eq!(dir.get_metadata(), &Metadata::new(time)); /// ``` @@ -237,7 +237,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = MemoryBlockStore::default(); /// /// dir @@ -345,7 +345,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let mut store = MemoryBlockStore::default(); /// /// dir @@ -395,7 +395,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = &MemoryBlockStore::default(); /// let cid = Cid::default(); /// @@ -443,7 +443,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = &MemoryBlockStore::default(); /// /// dir @@ -495,7 +495,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = MemoryBlockStore::default(); /// /// dir @@ -541,7 +541,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = MemoryBlockStore::default(); /// /// dir @@ -602,7 +602,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = MemoryBlockStore::default(); /// /// dir @@ -670,7 +670,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = MemoryBlockStore::default(); /// /// dir @@ -744,7 +744,7 @@ impl PublicDirectory { /// /// #[async_std::main] /// async fn main() -> Result<()> { - /// let dir = &mut PublicDirectory::rc(Utc::now()); + /// let dir = &mut PublicDirectory::new_rc(Utc::now()); /// let store = &MemoryBlockStore::new(); /// /// dir @@ -951,7 +951,7 @@ mod tests { #[async_std::test] async fn look_up_can_fetch_file_added_to_directory() { - let root_dir = &mut PublicDirectory::rc(Utc::now()); + let root_dir = &mut PublicDirectory::new_rc(Utc::now()); let store = MemoryBlockStore::default(); let content_cid = Cid::default(); let time = Utc::now(); @@ -967,7 +967,7 @@ mod tests { assert_eq!( node, - Some(&PublicNode::File(PublicFile::rc(time, content_cid))) + Some(&PublicNode::File(PublicFile::new_rc(time, content_cid))) ); } @@ -987,7 +987,7 @@ mod tests { async fn get_node_can_fetch_node_from_root_dir() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); root_dir .mkdir(&["pictures".into(), "dogs".into()], time, &store) @@ -1045,7 +1045,7 @@ mod tests { async fn mkdir_can_create_new_directory() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); root_dir .mkdir(&["tamedun".into(), "pictures".into()], time, &store) @@ -1064,7 +1064,7 @@ mod tests { async fn ls_can_list_children_under_directory() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); root_dir .mkdir(&["tamedun".into(), "pictures".into()], time, &store) @@ -1106,7 +1106,7 @@ mod tests { async fn rm_can_remove_children_from_directory() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let mut root_dir = PublicDirectory::rc(time); + let mut root_dir = PublicDirectory::new_rc(time); root_dir .mkdir(&["tamedun".into(), "pictures".into()], time, &store) @@ -1150,7 +1150,7 @@ mod tests { let store = MemoryBlockStore::default(); let content_cid = Cid::default(); let time = Utc::now(); - let mut root_dir = PublicDirectory::rc(time); + let mut root_dir = PublicDirectory::new_rc(time); root_dir .write(&["text.txt".into()], content_cid, time, &store) @@ -1166,7 +1166,7 @@ mod tests { async fn mv_can_move_sub_directory_to_another_valid_location() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let mut root_dir = PublicDirectory::rc(time); + let mut root_dir = PublicDirectory::new_rc(time); root_dir .write( @@ -1217,7 +1217,7 @@ mod tests { async fn mv_cannot_move_sub_directory_to_invalid_location() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let mut root_dir = PublicDirectory::rc(time); + let mut root_dir = PublicDirectory::new_rc(time); root_dir .mkdir( @@ -1249,7 +1249,7 @@ mod tests { async fn mv_can_rename_directories() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); root_dir .write(&["file.txt".into()], Cid::default(), time, &store) @@ -1278,7 +1278,7 @@ mod tests { async fn mv_fails_moving_directories_to_files() { let time = Utc::now(); let store = MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); root_dir .mkdir(&["movies".into(), "ghibli".into()], time, &store) @@ -1306,7 +1306,7 @@ mod tests { async fn previous_links_get_set() { let time = Utc::now(); let store = &MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); let previous_cid = root_dir.store(store).await.unwrap(); root_dir.mkdir(&["test".into()], time, store).await.unwrap(); @@ -1330,7 +1330,7 @@ mod tests { async fn prepare_next_revision_shortcuts_if_possible() { let time = Utc::now(); let store = &MemoryBlockStore::default(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); let previous_cid = &root_dir.store(store).await.unwrap(); let next_root_dir = root_dir.prepare_next_revision(); @@ -1355,7 +1355,7 @@ mod snapshot_tests { let store = &SnapshotBlockStore::default(); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); let cid = root_dir.store(store).await.unwrap(); let dir = store.get_block_snapshot(&cid).await.unwrap(); @@ -1368,7 +1368,7 @@ mod snapshot_tests { let store = &SnapshotBlockStore::default(); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); let paths = [ vec!["text.txt".into()], vec!["music".into(), "jazz".into()], @@ -1399,7 +1399,7 @@ mod snapshot_tests { vec!["videos".into(), "movies".into(), "anime".into()], ]; - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); let _ = root_dir.store(store).await.unwrap(); for path in paths.iter() { diff --git a/wnfs/src/public/file.rs b/wnfs/src/public/file.rs index 3da2fe89..b3560b65 100644 --- a/wnfs/src/public/file.rs +++ b/wnfs/src/public/file.rs @@ -71,7 +71,7 @@ impl PublicFile { /// /// println!("File: {:?}", file); /// ``` - pub fn rc(time: DateTime, content_cid: Cid) -> Rc { + pub fn new_rc(time: DateTime, content_cid: Cid) -> Rc { Rc::new(Self::new(time, content_cid)) } @@ -265,7 +265,7 @@ mod tests { .await .unwrap(); - let file = &mut PublicFile::rc(time, content_cid); + let file = &mut PublicFile::new_rc(time, content_cid); let previous_cid = &file.store(store).await.unwrap(); let next_file = file.prepare_next_revision(); @@ -284,7 +284,7 @@ mod tests { .await .unwrap(); - let file = &mut PublicFile::rc(time, content_cid); + let file = &mut PublicFile::new_rc(time, content_cid); let previous_cid = &file.store(store).await.unwrap(); let next_file = file.prepare_next_revision(); let next_file_clone = &mut Rc::new(next_file.clone()); @@ -308,7 +308,7 @@ mod snapshot_tests { let store = &SnapshotBlockStore::default(); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); - let file = &mut PublicFile::rc(time, Cid::default()); + let file = &mut PublicFile::new_rc(time, Cid::default()); let cid = file.store(store).await.unwrap(); let file = store.get_block_snapshot(&cid).await.unwrap(); @@ -321,7 +321,7 @@ mod snapshot_tests { let store = &SnapshotBlockStore::default(); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); - let file = &mut PublicFile::rc(time, Cid::default()); + let file = &mut PublicFile::new_rc(time, Cid::default()); let _ = file.store(store).await.unwrap(); file.write(time, Cid::default()); diff --git a/wnfs/src/public/node/node.rs b/wnfs/src/public/node/node.rs index 4f689151..4f113e5c 100644 --- a/wnfs/src/public/node/node.rs +++ b/wnfs/src/public/node/node.rs @@ -27,7 +27,7 @@ use wnfs_common::{AsyncSerialize, BlockStore, RemembersCid}; /// use wnfs::public::{PublicDirectory, PublicNode}; /// use chrono::Utc; /// -/// let dir = PublicDirectory::rc(Utc::now()); +/// let dir = PublicDirectory::new_rc(Utc::now()); /// let node = PublicNode::Dir(dir); /// /// println!("Node: {:?}", node); @@ -51,7 +51,7 @@ impl PublicNode { /// use wnfs::public::{PublicDirectory, PublicNode}; /// use chrono::{Utc, Duration, TimeZone}; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// let node = &mut PublicNode::Dir(dir); /// /// let time = Utc::now(); @@ -87,7 +87,7 @@ impl PublicNode { /// use libipld_core::cid::Cid; /// use std::{rc::Rc, collections::BTreeSet}; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// let node = PublicNode::Dir(dir); /// /// let new_cids = [Cid::default()]; @@ -123,7 +123,7 @@ impl PublicNode { /// use wnfs::public::{PublicDirectory, PublicNode}; /// use chrono::Utc; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// let node = PublicNode::Dir(dir); /// /// assert_eq!( @@ -149,7 +149,7 @@ impl PublicNode { /// use wnfs::public::{PublicDirectory, PublicNode}; /// use chrono::Utc; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// let node = PublicNode::Dir(Rc::clone(&dir)); /// /// assert_eq!(node.as_dir().unwrap(), dir); @@ -179,7 +179,7 @@ impl PublicNode { /// use chrono::Utc; /// use libipld_core::cid::Cid; /// - /// let file = PublicFile::rc(Utc::now(), Cid::default()); + /// let file = PublicFile::new_rc(Utc::now(), Cid::default()); /// let node = PublicNode::File(Rc::clone(&file)); /// /// assert_eq!(node.as_file().unwrap(), file); @@ -207,7 +207,7 @@ impl PublicNode { /// use wnfs::public::{PublicDirectory, PublicNode}; /// use chrono::Utc; /// - /// let dir = PublicDirectory::rc(Utc::now()); + /// let dir = PublicDirectory::new_rc(Utc::now()); /// let node = PublicNode::Dir(dir); /// /// assert!(node.is_dir()); @@ -225,7 +225,7 @@ impl PublicNode { /// use chrono::Utc; /// use libipld_core::cid::Cid; /// - /// let file = PublicFile::rc(Utc::now(), Cid::default()); + /// let file = PublicFile::new_rc(Utc::now(), Cid::default()); /// let node = PublicNode::File(file); /// /// assert!(node.is_file()); @@ -389,7 +389,7 @@ mod snapshot_tests { vec!["videos".into(), "movies".into(), "anime".into()], ]; - let root_dir = &mut PublicDirectory::rc(time); + let root_dir = &mut PublicDirectory::new_rc(time); let _ = root_dir.store(store).await.unwrap(); for path in paths.iter() { diff --git a/wnfs/src/root_tree.rs b/wnfs/src/root_tree.rs index d821eae7..ac668452 100644 --- a/wnfs/src/root_tree.rs +++ b/wnfs/src/root_tree.rs @@ -70,8 +70,8 @@ where store, rng, forest, - public_root: PublicDirectory::rc(time), - exchange_root: PublicDirectory::rc(time), + public_root: PublicDirectory::new_rc(time), + exchange_root: PublicDirectory::new_rc(time), private_map, } } @@ -350,8 +350,8 @@ impl<'a, B: BlockStore> RootTree<'a, B, ChaCha12Rng> { store, rng, forest, - public_root: PublicDirectory::rc(time), - exchange_root: PublicDirectory::rc(time), + public_root: PublicDirectory::new_rc(time), + exchange_root: PublicDirectory::new_rc(time), private_map: HashMap::default(), } }