Skip to content

Commit 57291ef

Browse files
feat: provide Into<String> for identifier types (#974)
* feat: provide `Into<String>` and `AsRef<str>` for identifier types * fix: use as_str on chain_id --------- Co-authored-by: Farhad Shabani <[email protected]>
1 parent 5a9937b commit 57291ef

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Provide `Into<String>` for all identifiers types.
2+
([\#974](https://github.com/cosmos/ibc-rs/pull/974))

ibc-core/ics24-host/types/src/identifiers/chain_id.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ impl FromStr for ChainId {
148148
}
149149
}
150150

151+
impl From<ChainId> for String {
152+
fn from(chain_id: ChainId) -> String {
153+
chain_id.id
154+
}
155+
}
156+
151157
impl Display for ChainId {
152158
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
153159
write!(f, "{}", self.id)

ibc-core/ics24-host/types/src/identifiers/channel_id.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::fmt::{Debug, Display, Error as FmtError, Formatter};
22
use core::str::FromStr;
33

4+
use derive_more::Into;
45
use ibc_primitives::prelude::*;
56

67
use crate::error::IdentifierError;
@@ -22,7 +23,7 @@ const CHANNEL_ID_PREFIX: &str = "channel";
2223
)]
2324
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2425
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
25-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
26+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)]
2627
pub struct ChannelId(String);
2728

2829
impl ChannelId {

ibc-core/ics24-host/types/src/identifiers/connection_id.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::fmt::{Display, Error as FmtError, Formatter};
22
use core::str::FromStr;
33

4+
use derive_more::Into;
45
use ibc_primitives::prelude::*;
56

67
use crate::error::IdentifierError;
@@ -22,7 +23,7 @@ const CONNECTION_ID_PREFIX: &str = "connection";
2223
)]
2324
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2425
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
25-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
26+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)]
2627
pub struct ConnectionId(String);
2728

2829
impl ConnectionId {

ibc-core/ics24-host/types/src/identifiers/port_id.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::fmt::{Display, Error as FmtError, Formatter};
22
use core::str::FromStr;
33

4+
use derive_more::Into;
45
use ibc_primitives::prelude::*;
56

67
use crate::error::IdentifierError;
@@ -22,7 +23,7 @@ const TRANSFER_PORT_ID: &str = "transfer";
2223
)]
2324
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2425
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
25-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
26+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)]
2627
pub struct PortId(String);
2728

2829
impl PortId {

ibc-testkit/src/hosts/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl HostBlock {
148148
let light_block = TestgenLightBlock::new_default_with_header(
149149
TestgenHeader::new(validators)
150150
.height(height)
151-
.chain_id(&chain_id.to_string())
151+
.chain_id(chain_id.as_str())
152152
.next_validators(next_validators)
153153
.time(timestamp.into_tm_time().expect("Never fails")),
154154
)

0 commit comments

Comments
 (0)