Skip to content

Commit

Permalink
refactor: Rename rc functions to new_rc
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Sep 4, 2023
1 parent 5f9ebd0 commit 549cec6
Show file tree
Hide file tree
Showing 21 changed files with 197 additions and 192 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions wnfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 9 additions & 12 deletions wnfs/examples/file_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions wnfs/examples/mnemonic_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn main() -> Result<()> {
async fn root_dir_setup(store: &impl BlockStore) -> Result<(Rc<HamtForest>, 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?;
Expand Down Expand Up @@ -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()],
Expand Down
4 changes: 2 additions & 2 deletions wnfs/examples/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion wnfs/examples/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions wnfs/examples/tiered_blockstores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
4 changes: 2 additions & 2 deletions wnfs/examples/write_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
6 changes: 3 additions & 3 deletions wnfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 549cec6

Please sign in to comment.