'How to return mapping in ton-solidity contracts?

Can I return a mapping in a function of ton-solidity contracts?

I need something like this.

function func() public returns((address=>someStruct) myMapping)


Solution 1:[1]

Contract.sol

pragma ton-solidity >= 0.51.0;
pragma AbiHeader expire;

struct someStruct {
    string foo;
    uint32 bar;
}

contract Contract {

    mapping (address => someStruct) _myMapping;

    constructor() public
    {
        tvm.accept();
        _myMapping[msg.sender] = someStruct("quz", now);
    }

    function func() external view returns(mapping (address=>someStruct))
    {
        return _myMapping;
    }
}

run.sh

#!/usr/bin/env bash

set -o errexit

tondev se reset

rm -fr *.abi.json *.tvc

# Deploy Contract
tondev sol compile Contract.sol
tondev contract deploy Contract --value 1000000000

# Run Contract
tondev contract run-local Contract func

Run

bash run.sh

Result

Execution has finished with result: {
    "output": {
        "value0": {
            "0:0000000000000000000000000000000000000000000000000000000000000000": {
                "foo": "quz",
                "bar": "1637140937"
            }
        }
    },
    "out_messages": []
}

Solution 2:[2]

This solved my problem:

function func() public returns(mapping (address=>someStruct))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ilyar
Solution 2 Jeremy Caney