Skip to content

Commit

Permalink
Fix clippy lints (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver E. Anderson committed Nov 2, 2022
1 parent afafa52 commit 29eaf57
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/1_advanced/1_did_issues_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn main() -> anyhow::Result<()> {

// Reconstruct the manufacturer's DID from the Alias Id.
let network: NetworkName = client.network_name().await?;
let manufacturer_did: IotaDID = IotaDID::new(&*manufacturer_alias_id, &network);
let manufacturer_did: IotaDID = IotaDID::new(&manufacturer_alias_id, &network);

// Resolve the issuer of the NFT.
let manufacturer_document: IotaDocument = client.resolve_did(&manufacturer_did).await?;
Expand Down
6 changes: 3 additions & 3 deletions identity_core/src/common/one_or_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<T> OneOrMany<T> {

/// Returns a reference to the contents as a slice.
pub fn as_slice(&self) -> &[T] {
&**self
self
}

/// Consumes the [`OneOrMany`] and returns the contents as a [`Vec`].
Expand Down Expand Up @@ -123,14 +123,14 @@ impl<T> Deref for OneOrMany<T> {
fn deref(&self) -> &Self::Target {
match self {
Self::One(inner) => from_ref(inner),
Self::Many(inner) => &**inner,
Self::Many(inner) => inner,
}
}
}

impl<T> AsRef<[T]> for OneOrMany<T> {
fn as_ref(&self) -> &[T] {
&**self
self
}
}

Expand Down
2 changes: 1 addition & 1 deletion identity_core/src/common/one_or_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ where

/// Returns a reference to the contents as a slice.
pub fn as_slice(&self) -> &[T] {
&**self
self
}

/// Consumes the [`OneOrSet`] and returns the contents as a [`Vec`].
Expand Down
4 changes: 2 additions & 2 deletions identity_core/src/common/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ impl Diff for Url {
self
.to_string()
.merge(diff)
.and_then(|this| Self::parse(&this).map_err(diff::Error::merge))
.and_then(|this| Self::parse(this).map_err(diff::Error::merge))
}

fn from_diff(diff: Self::Type) -> diff::Result<Self> {
String::from_diff(diff).and_then(|this| Self::parse(&this).map_err(diff::Error::convert))
String::from_diff(diff).and_then(|this| Self::parse(this).map_err(diff::Error::convert))
}

fn into_diff(self) -> diff::Result<Self::Type> {
Expand Down
2 changes: 1 addition & 1 deletion identity_core/src/crypto/key/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod tests {
#[test]
fn test_key_type_serde() {
for key_type in [KeyType::Ed25519, KeyType::X25519] {
let ser: Value = serde_json::to_value(&key_type).unwrap();
let ser: Value = serde_json::to_value(key_type).unwrap();
assert_eq!(ser.as_str().unwrap(), key_type.as_str());
let de: KeyType = serde_json::from_value(ser.clone()).unwrap();
assert_eq!(de, key_type);
Expand Down
4 changes: 2 additions & 2 deletions identity_core/src/crypto/proof/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ impl Proof {

/// Returns the `type` property of the proof.
pub fn type_(&self) -> &str {
&*self.type_
&self.type_
}

/// Returns the identifier of the DID method used to create this proof.
pub fn verification_method(&self) -> &str {
&*self.method
&self.method
}

/// Returns a reference to the proof `value`.
Expand Down
6 changes: 3 additions & 3 deletions identity_core/src/crypto/proof/proof_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ impl ProofValue {
pub fn as_str(&self) -> &str {
match self {
Self::None => "",
Self::Jws(inner) => &**inner,
Self::Proof(inner) => &**inner,
Self::Signature(inner) => &**inner,
Self::Jws(inner) => inner,
Self::Proof(inner) => inner,
Self::Signature(inner) => inner,
}
}

Expand Down
2 changes: 1 addition & 1 deletion identity_core/src/utils/base_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl BaseEncoding {
if data.as_ref().is_empty() {
return Ok(Vec::new());
}
multibase::decode(&data)
multibase::decode(data)
.map(|(_base, output)| output)
.map_err(Error::DecodeMultibase)
}
Expand Down
2 changes: 1 addition & 1 deletion identity_credential/src/credential/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct Credential<T = Object> {
impl<T> Credential<T> {
/// Returns the base JSON-LD context.
pub fn base_context() -> &'static Context {
&*BASE_CONTEXT
&BASE_CONTEXT
}

/// Returns the base type.
Expand Down
2 changes: 1 addition & 1 deletion identity_credential/src/validator/credential_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl CredentialValidator {
OneOrMany::One(ref credential_subject) => credential_subject.id.as_ref() == Some(holder),
OneOrMany::Many(subjects) => {
// need to check the case where the Many variant holds a vector of exactly one subject
if let &[ref credential_subject] = subjects.as_slice() {
if let [credential_subject] = subjects.as_slice() {
credential_subject.id.as_ref() == Some(holder)
} else {
// zero or > 1 subjects is interpreted to mean that the holder is not the subject
Expand Down
6 changes: 1 addition & 5 deletions identity_credential/src/validator/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ use crate::credential::Subject;

pub(super) fn generate_document_with_keys() -> (CoreDocument, KeyPair) {
let keypair: KeyPair = KeyPair::new(KeyType::Ed25519).unwrap();
let did: CoreDID = CoreDID::parse(&format!(
"did:example:{}",
BaseEncoding::encode_base58(keypair.public())
))
.unwrap();
let did: CoreDID = CoreDID::parse(format!("did:example:{}", BaseEncoding::encode_base58(keypair.public()))).unwrap();
let document: CoreDocument = CoreDocument::builder(Object::new())
.id(did.clone())
.verification_method(VerificationMethod::new(did, KeyType::Ed25519, keypair.public(), "#root").unwrap())
Expand Down
6 changes: 3 additions & 3 deletions identity_did/src/did/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ impl Diff for CoreDID {
self
.to_string()
.merge(diff)
.and_then(|this| Self::parse(&this).map_err(identity_core::diff::Error::merge))
.and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::merge))
}

fn from_diff(diff: Self::Type) -> identity_core::diff::Result<Self> {
String::from_diff(diff).and_then(|this| Self::parse(&this).map_err(identity_core::diff::Error::convert))
String::from_diff(diff).and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::convert))
}

fn into_diff(self) -> identity_core::diff::Result<Self::Type> {
Expand Down Expand Up @@ -373,7 +373,7 @@ mod tests {

#[test]
fn test_fuzz_core_did_no_panic(s in "\\PC*") {
assert!(CoreDID::parse(&s).is_err());
assert!(CoreDID::parse(s).is_err());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions identity_did/src/did/did_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,11 @@ where
self
.to_string()
.merge(diff)
.and_then(|this| Self::parse(&this).map_err(identity_core::diff::Error::merge))
.and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::merge))
}

fn from_diff(diff: Self::Type) -> identity_core::diff::Result<Self> {
String::from_diff(diff).and_then(|this| Self::parse(&this).map_err(identity_core::diff::Error::convert))
String::from_diff(diff).and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::convert))
}

fn into_diff(self) -> identity_core::diff::Result<Self::Type> {
Expand Down Expand Up @@ -871,7 +871,7 @@ mod tests {
#[test]
fn test_fuzz_join_no_panic(s in "\\PC*") {
let did_url = CoreDIDUrl::parse("did:example:1234567890").unwrap();
let _ = did_url.join(&s);
let _ = did_url.join(s);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion identity_did/src/revocation/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl RevocationBitmap {
/// Serializes and compressess [`RevocationBitmap`] as a base64-encoded `String`.
pub(crate) fn serialize_compressed_base64(&self) -> Result<String> {
let serialized_data: Vec<u8> = self.serialize_vec()?;
Self::compress_zlib(&serialized_data).map(|data| BaseEncoding::encode(&data, Base::Base64Url))
Self::compress_zlib(serialized_data).map(|data| BaseEncoding::encode(&data, Base::Base64Url))
}

/// Deserializes [`RevocationBitmap`] from a slice of bytes.
Expand Down
2 changes: 1 addition & 1 deletion identity_did/src/verification/method_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {
MethodType::Ed25519VerificationKey2018,
MethodType::X25519KeyAgreementKey2019,
] {
let ser: Value = serde_json::to_value(&method_type).unwrap();
let ser: Value = serde_json::to_value(method_type).unwrap();
assert_eq!(ser.as_str().unwrap(), method_type.as_str());
let de: MethodType = serde_json::from_value(ser.clone()).unwrap();
assert_eq!(de, method_type);
Expand Down
18 changes: 12 additions & 6 deletions identity_iota_core/src/client/iota_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl IotaClientExt for Client {
) -> Result<IotaDocument> {
let block: Block = publish_output(self, secret_manager, alias_output)
.await
.map_err(|err| Error::DIDUpdateError("publish_did_output: publish failed", Some(err)))?;
.map_err(|err| Error::DIDUpdateError("publish_did_output: publish failed", Some(Box::new(err))))?;
let network: NetworkName = self.network_name().await?;

IotaDocument::unpack_from_block(&network, &block)?
Expand Down Expand Up @@ -92,17 +92,22 @@ impl IotaClientExt for Client {
.block()
.with_secret_manager(secret_manager)
.with_input(output_id.into())
.map_err(|err| Error::DIDUpdateError("delete_did_output: invalid block input", Some(err)))?
.map_err(|err| Error::DIDUpdateError("delete_did_output: invalid block input", Some(Box::new(err))))?
.with_outputs(vec![basic_output])
.map_err(|err| Error::DIDUpdateError("delete_did_output: invalid block output", Some(err)))?
.map_err(|err| Error::DIDUpdateError("delete_did_output: invalid block output", Some(Box::new(err))))?
.with_burning_allowed(true)
.finish()
.await
.map_err(|err| Error::DIDUpdateError("delete_did_output: publish failed", Some(err)))?;
.map_err(|err| Error::DIDUpdateError("delete_did_output: publish failed", Some(Box::new(err))))?;
let _ = self
.retry_until_included(&block.id(), None, None)
.await
.map_err(|err| Error::DIDUpdateError("delete_did_output: publish retry failed or timed-out", Some(err)))?;
.map_err(|err| {
Error::DIDUpdateError(
"delete_did_output: publish retry failed or timed-out",
Some(Box::new(err)),
)
})?;

Ok(())
}
Expand Down Expand Up @@ -132,7 +137,8 @@ impl IotaIdentityClient for Client {
}

async fn get_rent_structure(&self) -> Result<RentStructure> {
Client::get_rent_structure(self).map_err(|err| Error::DIDUpdateError("get_rent_structure failed", Some(err)))
Client::get_rent_structure(self)
.map_err(|err| Error::DIDUpdateError("get_rent_structure failed", Some(Box::new(err))))
}
async fn get_token_supply(&self) -> Result<u64> {
self.get_token_supply().map_err(Error::TokenSupplyError)
Expand Down
10 changes: 5 additions & 5 deletions identity_iota_core/src/did/iota_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ mod tests {
network_name
);
let did_core: CoreDID = {
match CoreDID::parse(&did_string) {
match CoreDID::parse(did_string) {
Ok(did_core) => did_core,
Err(_) => continue,
}
Expand Down Expand Up @@ -464,8 +464,8 @@ mod tests {
// nothing/normalized)>:<alias_id>
let did_other_string: String = format!("did:method:{}", VALID_ALIAS_ID_STR);
let did_other_with_network: String = format!("did:method:test:{}", VALID_ALIAS_ID_STR);
let did_other_core: CoreDID = CoreDID::parse(&did_other_string).unwrap();
let did_other_with_network_core: CoreDID = CoreDID::parse(&did_other_with_network).unwrap();
let did_other_core: CoreDID = CoreDID::parse(did_other_string).unwrap();
let did_other_with_network_core: CoreDID = CoreDID::parse(did_other_with_network).unwrap();

assert!(IotaDID::check_tag(&did_other_core).is_ok());
assert!(IotaDID::check_tag(&did_other_with_network_core).is_ok());
Expand Down Expand Up @@ -541,7 +541,7 @@ mod tests {
#[test]
fn parse_valid() {
for did_str in VALID_IOTA_DID_STRINGS.iter() {
assert!(IotaDID::parse(&did_str).is_ok());
assert!(IotaDID::parse(did_str).is_ok());
}
}

Expand Down Expand Up @@ -609,7 +609,7 @@ mod tests {
#[test]
fn property_based_valid_parse(alias_id in arbitrary_alias_id()) {
let did: String = format!("did:{}:{}",IotaDID::METHOD, alias_id);
assert!(IotaDID::parse(&did).is_ok());
assert!(IotaDID::parse(did).is_ok());
}
}

Expand Down
2 changes: 1 addition & 1 deletion identity_iota_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum Error {
InvalidDoc(#[from] identity_did::Error),
#[cfg(feature = "iota-client")]
#[error("DID update: {0}")]
DIDUpdateError(&'static str, #[source] Option<iota_client::error::Error>),
DIDUpdateError(&'static str, #[source] Option<Box<iota_client::error::Error>>),
#[cfg(feature = "iota-client")]
#[error("DID resolution failed")]
DIDResolutionError(#[source] iota_client::error::Error),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ where
#[tokio::test]
async fn missing_handler_errors() {
let method_name: String = "foo".to_owned();
let bad_did: CoreDID = CoreDID::parse(&format!("did:{method_name}:1234")).unwrap();
let bad_did: CoreDID = CoreDID::parse(format!("did:{method_name}:1234")).unwrap();
let other_method: String = "bar".to_owned();
let good_did: CoreDID = CoreDID::parse(format!("did:{other_method}:1234")).unwrap();
// configure `resolver` to resolve the "bar" method
Expand Down

0 comments on commit 29eaf57

Please sign in to comment.