Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abigen finds std::string::String over sway-lib's String #686

Closed
bitzoic opened this issue Nov 7, 2022 · 1 comment · Fixed by #763
Closed

Abigen finds std::string::String over sway-lib's String #686

bitzoic opened this issue Nov 7, 2022 · 1 comment · Fixed by #763
Assignees
Labels
abigen bug Something isn't working

Comments

@bitzoic
Copy link
Member

bitzoic commented Nov 7, 2022

When attempting to pass or return the sway-libs String type, abigen mistakes this for Rust's standard library string.

For example, running a test on the following Sway code generates this error:

contract;

use sway_libs::string::String;

abi MyContract {
    fn test_get() -> String;
    fn test_set(new_string: String);
}

impl MyContract for Contract {
    fn test_get() -> String {
        String::new()
    }

    fn test_set(new_string: String) {
        
    }
}

strings_test_error

The Sway-lib's String is currently simply a wrapper on Sway's Vec:

pub struct String {
    bytes: Vec<u8>,
}
@bitzoic bitzoic added bug Something isn't working abigen labels Nov 7, 2022
@segfault-magnet segfault-magnet self-assigned this Nov 7, 2022
@segfault-magnet
Copy link
Contributor

@bitzoic there is a problem with the name collision, so I'll fix that in this task.

But note that you can't return anything containing a vector until this task is done.

Even then I fear you won't be able to return this as there was an inter-team meeting on which we agreed that returning vectors will be supported only at the topmost level -- i.e. fn something() -> Vec<Something>

Even though the nesting of the vec inside Sway's string is superficial (i.e. it will be encoded exactly as a top-level-vec would be), this still might be prohibited by the compiler once the 'vec-as-output' support is done on the Sway side.

@mohammadfawaz fyi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abigen bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants