Skip to content

Commit

Permalink
[feature] hyperledger#2073: Prefer ConstString over String for data_m…
Browse files Browse the repository at this point in the history
…odel

Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
  • Loading branch information
ales-tsurko committed Jul 19, 2022
1 parent 64d0993 commit 27bc564
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions data_model/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use core::{cmp::Ordering, str::FromStr};
use derive_more::{Display, FromStr};
use getset::{Getters, MutGetters};
use iroha_crypto::PublicKey;
use iroha_data_primitives::conststr::ConstString;
#[cfg(feature = "ffi_api")]
use iroha_ffi::ffi_bindgen;
use iroha_schema::IntoSchema;
Expand Down Expand Up @@ -339,7 +340,7 @@ impl FromIterator<Domain> for crate::Value {
/// Represents path in IPFS. Performs checks to ensure path validity.
/// Construct using [`FromStr::from_str`] method.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Serialize, IntoSchema)]
pub struct IpfsPath(String);
pub struct IpfsPath(ConstString);

impl FromStr for IpfsPath {
type Err = ParseError;
Expand Down Expand Up @@ -376,7 +377,7 @@ impl FromStr for IpfsPath {
Self::check_cid(path)?;
}

Ok(IpfsPath(String::from(string)))
Ok(IpfsPath(ConstString::from(string)))
}
}

Expand Down Expand Up @@ -420,7 +421,7 @@ impl<'de> Deserialize<'de> for IpfsPath {

impl Decode for IpfsPath {
fn decode<I: Input>(input: &mut I) -> Result<Self, parity_scale_codec::Error> {
let name = String::decode(input)?;
let name = ConstString::decode(input)?;
Self::from_str(&name).map_err(|error| error.reason.into())
}
}
Expand Down Expand Up @@ -516,7 +517,7 @@ mod tests {
#[test]
fn deserialize_ipfs() {
for invalid_ipfs in INVALID_IPFS {
let invalid_ipfs = IpfsPath(invalid_ipfs.to_owned());
let invalid_ipfs = IpfsPath(invalid_ipfs.into());
let serialized = serde_json::to_string(&invalid_ipfs).expect("Valid");
let ipfs = serde_json::from_str::<IpfsPath>(serialized.as_str());

Expand All @@ -527,7 +528,7 @@ mod tests {
#[test]
fn decode_ipfs() {
for invalid_ipfs in INVALID_IPFS {
let invalid_ipfs = IpfsPath(invalid_ipfs.to_owned());
let invalid_ipfs = IpfsPath(invalid_ipfs.into());
let bytes = invalid_ipfs.encode();
let ipfs = IpfsPath::decode(&mut &bytes[..]);

Expand Down
2 changes: 1 addition & 1 deletion data_model/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{ParseError, ValidationError};
pub struct Name(ConstString);

impl Name {
/// Check if `range` contains the number of chars in the inner `String` of this [`Name`].
/// Check if `range` contains the number of chars in the inner `ConstString` of this [`Name`].
///
/// # Errors
/// Fails if `range` does not
Expand Down

0 comments on commit 27bc564

Please sign in to comment.