Skip to content

Commit 12425c1

Browse files
authored
feat: implement TryIntoAccountId for &String (#59)
1 parent 6f72959 commit 12425c1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/into_account_id.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ impl TryIntoAccountId for String {
121121
}
122122
}
123123

124+
impl TryIntoAccountId for &String {
125+
fn try_into_account_id(self) -> Result<crate::AccountId, crate::ParseAccountError> {
126+
self.as_str().parse()
127+
}
128+
129+
fn as_str(&self) -> &str {
130+
self
131+
}
132+
}
133+
124134
impl TryIntoAccountId for std::borrow::Cow<'_, crate::AccountIdRef> {
125135
fn try_into_account_id(self) -> Result<crate::AccountId, crate::ParseAccountError> {
126136
Ok(self.into())
@@ -182,6 +192,16 @@ mod tests {
182192
assert_eq!(result.unwrap(), "bob.near");
183193
}
184194

195+
#[test]
196+
fn test_borrowed_string() {
197+
let account_string = String::from("bob.near");
198+
let result = accept_account(&account_string);
199+
assert!(result.is_ok());
200+
assert_eq!(result.unwrap(), "bob.near");
201+
// Original still exists
202+
assert_eq!(account_string, "bob.near");
203+
}
204+
185205
#[test]
186206
fn test_invalid_str_ref() {
187207
let account_str = "a";

0 commit comments

Comments
 (0)