File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff 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+
124134impl 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" ;
You can’t perform that action at this time.
0 commit comments