You can instantiate the mapping (defined in your Test
library) into your smart contract and then you can handle all data inside it.
Below you can see an example how to do this:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library Test{
struct Data {
mapping (bytes => string) a;
}
function inc(Data storage self) internal {
self.a['0'] = "ban";
self.a['1'] = "sam";
}
}
contract Example{
address recipient = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
// NOTE: Declare a new instance about mapping inside Data struct in 'Test' library
Test.Data Datastruct;
// NOTE: Function that allow you to call 'inc' function inside 'Test' Library for fill the mapping
function setName() public {
Test.inc(Datastruct);
}
function getNames() external view returns(string memory) {
// NOTE: With instance about mapping, you can read data
return Datastruct.a['0'];
}
}
I put NOTES for make you understand the different steps that I made.