diff --git a/rust/noosphere-common/src/channel.rs b/rust/noosphere-common/src/channel.rs index 16b77c24b..5ea79cf9f 100644 --- a/rust/noosphere-common/src/channel.rs +++ b/rust/noosphere-common/src/channel.rs @@ -143,7 +143,7 @@ pub fn message_channel() -> (MessageClient, MessageProcessor { + Request::SetFlag() => { set_flags += 1; let success = m.respond(Ok(Response::GenericResult(true))); assert!( @@ -199,8 +199,8 @@ mod tests { let res = client.send(Request::Ping()).await?; matches!(res, Ok(Response::Pong())); - for n in 0..10 { - client.send_oneshot(Request::SetFlag(n))?; + for _ in 0..10 { + client.send_oneshot(Request::SetFlag())?; } let res = client.send(Request::Throw()).await?; diff --git a/rust/noosphere-core/src/api/v0alpha1/data.rs b/rust/noosphere-core/src/api/v0alpha1/data.rs index dd4d979f5..fdf5f6c74 100644 --- a/rust/noosphere-core/src/api/v0alpha1/data.rs +++ b/rust/noosphere-core/src/api/v0alpha1/data.rs @@ -7,7 +7,6 @@ use crate::api::{ use crate::{ authority::{generate_capability, SphereAbility, SPHERE_SEMANTICS}, data::{Bundle, Did, Jwt, Link, MemoIpld}, - error::NoosphereError, }; use anyhow::{anyhow, Result}; use cid::Cid; @@ -174,12 +173,6 @@ pub enum PushError { Internal(anyhow::Error), } -impl From for PushError { - fn from(error: NoosphereError) -> Self { - error.into() - } -} - impl From for PushError { fn from(value: anyhow::Error) -> Self { PushError::Internal(value) diff --git a/rust/noosphere-core/src/api/v0alpha2/data.rs b/rust/noosphere-core/src/api/v0alpha2/data.rs index ba955fa4d..203d3bbfd 100644 --- a/rust/noosphere-core/src/api/v0alpha2/data.rs +++ b/rust/noosphere-core/src/api/v0alpha2/data.rs @@ -1,7 +1,6 @@ use crate::{ api::StatusCode, data::{Did, Jwt, Link, MemoIpld}, - error::NoosphereError, }; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -72,12 +71,6 @@ impl From<&PushError> for StatusCode { } } -impl From for PushError { - fn from(error: NoosphereError) -> Self { - error.into() - } -} - impl From for PushError { fn from(value: anyhow::Error) -> Self { PushError::Internal(Some(format!("{value}"))) diff --git a/rust/noosphere-core/src/helpers/context.rs b/rust/noosphere-core/src/helpers/context.rs index 3f95d8bfb..786269b5e 100644 --- a/rust/noosphere-core/src/helpers/context.rs +++ b/rust/noosphere-core/src/helpers/context.rs @@ -48,7 +48,7 @@ pub async fn simulated_sphere_context( /// Generate a [SphereContext] using the storage provided, intended for tests and /// benchmarks. You can pass a [Access] to control access. -pub async fn generate_sphere_context( +pub async fn generate_sphere_context( profile: Access, mut db: SphereDb, ) -> Result<(Arc>>, Mnemonic)> { diff --git a/rust/noosphere-core/src/view/mutation.rs b/rust/noosphere-core/src/view/mutation.rs index 8b84f58c8..925add372 100644 --- a/rust/noosphere-core/src/view/mutation.rs +++ b/rust/noosphere-core/src/view/mutation.rs @@ -258,7 +258,7 @@ where )); } - self.changes = changelog.changes.clone(); + self.changes.clone_from(&changelog.changes); Ok(()) } diff --git a/rust/noosphere-ns/src/bin/orb-ns/runner/config.rs b/rust/noosphere-ns/src/bin/orb-ns/runner/config.rs index 387a1dc79..ec764aa32 100644 --- a/rust/noosphere-ns/src/bin/orb-ns/runner/config.rs +++ b/rust/noosphere-ns/src/bin/orb-ns/runner/config.rs @@ -66,13 +66,7 @@ impl RunnerNodeConfig { None => { let key_name: String = key.ok_or_else(|| anyhow!("--key or --config must be provided."))?; - - let bootstrap_peers = if let Some(peers) = peers { - peers - } else { - vec![] - }; - + let bootstrap_peers = peers.unwrap_or_default(); let dht_config = DhtConfig::default(); let config = CLIConfigFile { diff --git a/rust/noosphere/src/ffi/context.rs b/rust/noosphere/src/ffi/context.rs index 0070d191c..cfd920603 100644 --- a/rust/noosphere/src/ffi/context.rs +++ b/rust/noosphere/src/ffi/context.rs @@ -212,10 +212,7 @@ pub fn ns_sphere_traverse_by_petname_blocking( Ok(sphere) }; - match error_out.try_or_initialize(closure) { - Some(maybe_sphere) => maybe_sphere, - None => None, - } + error_out.try_or_initialize(closure).unwrap_or_default() } #[ffi_export] @@ -315,48 +312,49 @@ pub fn ns_sphere_content_read_blocking( slashlink: char_p::Ref<'_>, error_out: Option>>, ) -> Option> { - match error_out.try_or_initialize(|| { - noosphere - .async_runtime() - .block_on(async { - let slashlink = Slashlink::from_str(slashlink.to_str())?; - - let slug = match slashlink.slug { - Some(slug) => slug, - None => return Err(anyhow!("No slug specified in slashlink!")), - }; - - let cursor = match slashlink.peer { - Peer::Name(petnames) => { - match sphere.inner().traverse_by_petnames(&petnames).await? { - Some(sphere_context) => sphere_context, - None => return Ok(None), + error_out + .try_or_initialize(|| { + noosphere + .async_runtime() + .block_on(async { + let slashlink = Slashlink::from_str(slashlink.to_str())?; + + let slug = match slashlink.slug { + Some(slug) => slug, + None => return Err(anyhow!("No slug specified in slashlink!")), + }; + + let cursor = match slashlink.peer { + Peer::Name(petnames) => { + match sphere.inner().traverse_by_petnames(&petnames).await? { + Some(sphere_context) => sphere_context, + None => return Ok(None), + } } - } - Peer::None => sphere.inner().clone(), - Peer::Did(_) => return Err(anyhow!("DID peer in slashlink not yet supported")), - }; - - info!( - "Reading sphere {} slug {}...", - cursor.identity().await?, - slug - ); - - let file = cursor.read(&slug).await?; - - Ok(file.map(|sphere_file| { - Box::new(NsSphereFile { - inner: sphere_file.boxed(), - }) - .into() - })) - }) - .map_err(|error| error.into()) - }) { - Some(maybe_file) => maybe_file, - None => None, - } + Peer::None => sphere.inner().clone(), + Peer::Did(_) => { + return Err(anyhow!("DID peer in slashlink not yet supported")) + } + }; + + info!( + "Reading sphere {} slug {}...", + cursor.identity().await?, + slug + ); + + let file = cursor.read(&slug).await?; + + Ok(file.map(|sphere_file| { + Box::new(NsSphereFile { + inner: sphere_file.boxed(), + }) + .into() + })) + }) + .map_err(|error| error.into()) + }) + .unwrap_or_default() } #[ffi_export] @@ -467,28 +465,25 @@ pub fn ns_sphere_content_list( sphere: &NsSphere, error_out: Option>>, ) -> c_slice::Box { - let possible_output = error_out.try_or_initialize(|| { - noosphere.async_runtime().block_on(async { - let slug_set = SphereWalker::from(sphere.inner()).list_slugs().await?; - let mut all_slugs: Vec = Vec::new(); - - for slug in slug_set.into_iter() { - all_slugs.push( - slug.try_into() - .map_err(|error: InvalidNulTerminator| anyhow!(error))?, - ); - } - - Ok(all_slugs) + error_out + .try_or_initialize(|| { + noosphere.async_runtime().block_on(async { + let slug_set = SphereWalker::from(sphere.inner()).list_slugs().await?; + let mut all_slugs: Vec = Vec::new(); + + for slug in slug_set.into_iter() { + all_slugs.push( + slug.try_into() + .map_err(|error: InvalidNulTerminator| anyhow!(error))?, + ); + } + + Ok(all_slugs) + }) }) - }); - - match possible_output { - Some(slugs) => slugs, - None => Vec::new(), - } - .into_boxed_slice() - .into() + .unwrap_or_default() + .into_boxed_slice() + .into() } #[ffi_export] @@ -509,39 +504,36 @@ pub fn ns_sphere_content_changes( since_cid: Option>, error_out: Option>>, ) -> c_slice::Box { - let possible_output = error_out.try_or_initialize(|| { - noosphere.async_runtime().block_on(async { - let since = match since_cid { - Some(cid_string) => Some( - Cid::from_str(cid_string.to_str()) - .map_err(|error| anyhow!(error))? - .into(), - ), - None => None, - }; + error_out + .try_or_initialize(|| { + noosphere.async_runtime().block_on(async { + let since = match since_cid { + Some(cid_string) => Some( + Cid::from_str(cid_string.to_str()) + .map_err(|error| anyhow!(error))? + .into(), + ), + None => None, + }; - let changed_slug_set = SphereWalker::from(sphere.inner()) - .content_changes(since.as_ref()) - .await?; - let mut changed_slugs: Vec = Vec::new(); + let changed_slug_set = SphereWalker::from(sphere.inner()) + .content_changes(since.as_ref()) + .await?; + let mut changed_slugs: Vec = Vec::new(); - for slug in changed_slug_set.into_iter() { - changed_slugs.push( - slug.try_into() - .map_err(|error: InvalidNulTerminator| anyhow!(error))?, - ); - } + for slug in changed_slug_set.into_iter() { + changed_slugs.push( + slug.try_into() + .map_err(|error: InvalidNulTerminator| anyhow!(error))?, + ); + } - Ok(changed_slugs) + Ok(changed_slugs) + }) }) - }); - - match possible_output { - Some(slugs) => slugs, - None => Vec::new(), - } - .into_boxed_slice() - .into() + .unwrap_or_default() + .into_boxed_slice() + .into() } #[ffi_export] diff --git a/rust/noosphere/src/ffi/petname.rs b/rust/noosphere/src/ffi/petname.rs index c47511eae..03a5aa107 100644 --- a/rust/noosphere/src/ffi/petname.rs +++ b/rust/noosphere/src/ffi/petname.rs @@ -192,10 +192,7 @@ pub fn ns_sphere_petname_resolve( Ok(None) } }; - match error_out.try_or_initialize(closure) { - Some(maybe_version) => maybe_version, - None => None, - } + error_out.try_or_initialize(closure).unwrap_or_default() } #[ffi_export] @@ -207,29 +204,26 @@ pub fn ns_sphere_petname_list( sphere: &NsSphere, error_out: Option>>, ) -> c_slice::Box { - let possible_output = error_out.try_or_initialize(|| { - noosphere.async_runtime().block_on(async { - let petname_set = SphereWalker::from(sphere.inner()).list_petnames().await?; - let mut all_petnames: Vec = Vec::new(); + error_out + .try_or_initialize(|| { + noosphere.async_runtime().block_on(async { + let petname_set = SphereWalker::from(sphere.inner()).list_petnames().await?; + let mut all_petnames: Vec = Vec::new(); - for petname in petname_set.into_iter() { - all_petnames.push( - petname - .try_into() - .map_err(|error: InvalidNulTerminator| anyhow!(error))?, - ); - } + for petname in petname_set.into_iter() { + all_petnames.push( + petname + .try_into() + .map_err(|error: InvalidNulTerminator| anyhow!(error))?, + ); + } - Ok(all_petnames) + Ok(all_petnames) + }) }) - }); - - match possible_output { - Some(slugs) => slugs, - None => Vec::new(), - } - .into_boxed_slice() - .into() + .unwrap_or_default() + .into_boxed_slice() + .into() } #[ffi_export] @@ -254,38 +248,35 @@ pub fn ns_sphere_petname_changes( since_cid: Option>, error_out: Option>>, ) -> c_slice::Box { - let possible_output = error_out.try_or_initialize(|| { - noosphere.async_runtime().block_on(async { - let since = match since_cid { - Some(cid_string) => Some( - Cid::from_str(cid_string.to_str()) - .map_err(|error| anyhow!(error))? - .into(), - ), - None => None, - }; + error_out + .try_or_initialize(|| { + noosphere.async_runtime().block_on(async { + let since = match since_cid { + Some(cid_string) => Some( + Cid::from_str(cid_string.to_str()) + .map_err(|error| anyhow!(error))? + .into(), + ), + None => None, + }; - let changed_petname_set = SphereWalker::from(sphere.inner()) - .petname_changes(since.as_ref()) - .await?; - let mut changed_petnames: Vec = Vec::new(); + let changed_petname_set = SphereWalker::from(sphere.inner()) + .petname_changes(since.as_ref()) + .await?; + let mut changed_petnames: Vec = Vec::new(); - for petname in changed_petname_set.into_iter() { - changed_petnames.push( - petname - .try_into() - .map_err(|error: InvalidNulTerminator| anyhow!(error))?, - ); - } + for petname in changed_petname_set.into_iter() { + changed_petnames.push( + petname + .try_into() + .map_err(|error: InvalidNulTerminator| anyhow!(error))?, + ); + } - Ok(changed_petnames) + Ok(changed_petnames) + }) }) - }); - - match possible_output { - Some(petnames) => petnames, - None => Vec::new(), - } - .into_boxed_slice() - .into() + .unwrap_or_default() + .into_boxed_slice() + .into() } diff --git a/rust/noosphere/src/platform.rs b/rust/noosphere/src/platform.rs index 277ad9c11..7c084a3da 100644 --- a/rust/noosphere/src/platform.rs +++ b/rust/noosphere/src/platform.rs @@ -4,9 +4,8 @@ //! use on a per-platform basis. #[cfg(apple)] +#[allow(missing_docs)] mod inner { - #![allow(missing_docs)] - use noosphere_ucan::key_material::ed25519::Ed25519KeyMaterial; use crate::key::InsecureKeyStorage; @@ -50,8 +49,8 @@ mod inner { } #[cfg(wasm)] +#[allow(missing_docs)] mod inner { - #![allow(missing_docs)] use crate::key::WebCryptoKeyStorage;