Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
chore: Fix nightly lints for 2024-03-11, 2024-03-24 (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell authored Mar 25, 2024
1 parent 83cde32 commit 5b52cc8
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 179 deletions.
8 changes: 4 additions & 4 deletions rust/noosphere-common/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn message_channel<Q, S, E>() -> (MessageClient<Q, S, E>, MessageProcessor<Q
mod tests {
enum Request {
Ping(),
SetFlag(u32),
SetFlag(),
Shutdown(),
Throw(),
}
Expand Down Expand Up @@ -176,7 +176,7 @@ mod tests {
message: String::from("thrown!"),
}));
}
Request::SetFlag(_) => {
Request::SetFlag() => {
set_flags += 1;
let success = m.respond(Ok(Response::GenericResult(true)));
assert!(
Expand All @@ -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?;
Expand Down
7 changes: 0 additions & 7 deletions rust/noosphere-core/src/api/v0alpha1/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,12 +173,6 @@ pub enum PushError {
Internal(anyhow::Error),
}

impl From<NoosphereError> for PushError {
fn from(error: NoosphereError) -> Self {
error.into()
}
}

impl From<anyhow::Error> for PushError {
fn from(value: anyhow::Error) -> Self {
PushError::Internal(value)
Expand Down
7 changes: 0 additions & 7 deletions rust/noosphere-core/src/api/v0alpha2/data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
api::StatusCode,
data::{Did, Jwt, Link, MemoIpld},
error::NoosphereError,
};
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -72,12 +71,6 @@ impl From<&PushError> for StatusCode {
}
}

impl From<NoosphereError> for PushError {
fn from(error: NoosphereError) -> Self {
error.into()
}
}

impl From<anyhow::Error> for PushError {
fn from(value: anyhow::Error) -> Self {
PushError::Internal(Some(format!("{value}")))
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-core/src/helpers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Storage>(
pub async fn generate_sphere_context<S: Storage + 'static>(
profile: Access,
mut db: SphereDb<S>,
) -> Result<(Arc<Mutex<SphereContext<S>>>, Mnemonic)> {
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-core/src/view/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ where
));
}

self.changes = changelog.changes.clone();
self.changes.clone_from(&changelog.changes);

Ok(())
}
Expand Down
8 changes: 1 addition & 7 deletions rust/noosphere-ns/src/bin/orb-ns/runner/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
182 changes: 87 additions & 95 deletions rust/noosphere/src/ffi/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -315,48 +312,49 @@ pub fn ns_sphere_content_read_blocking(
slashlink: char_p::Ref<'_>,
error_out: Option<Out<'_, repr_c::Box<NsError>>>,
) -> Option<repr_c::Box<NsSphereFile>> {
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]
Expand Down Expand Up @@ -467,28 +465,25 @@ pub fn ns_sphere_content_list(
sphere: &NsSphere,
error_out: Option<Out<'_, repr_c::Box<NsError>>>,
) -> c_slice::Box<char_p::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<char_p::Box> = Vec::new();

for slug in slug_set.into_iter() {
all_slugs.push(
slug.try_into()
.map_err(|error: InvalidNulTerminator<String>| 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<char_p::Box> = Vec::new();

for slug in slug_set.into_iter() {
all_slugs.push(
slug.try_into()
.map_err(|error: InvalidNulTerminator<String>| 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]
Expand All @@ -509,39 +504,36 @@ pub fn ns_sphere_content_changes(
since_cid: Option<char_p::Ref<'_>>,
error_out: Option<Out<'_, repr_c::Box<NsError>>>,
) -> c_slice::Box<char_p::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<char_p::Box> = Vec::new();
let changed_slug_set = SphereWalker::from(sphere.inner())
.content_changes(since.as_ref())
.await?;
let mut changed_slugs: Vec<char_p::Box> = Vec::new();

for slug in changed_slug_set.into_iter() {
changed_slugs.push(
slug.try_into()
.map_err(|error: InvalidNulTerminator<String>| anyhow!(error))?,
);
}
for slug in changed_slug_set.into_iter() {
changed_slugs.push(
slug.try_into()
.map_err(|error: InvalidNulTerminator<String>| 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]
Expand Down
Loading

0 comments on commit 5b52cc8

Please sign in to comment.