The library provides Cell and BagOfCell support for interacting with TON data structures. Use CellBuilder to construct a cell by writing various data types (integers, bits, slices, addresses, strings) and then call .build() to finalize it. To read data, use the .parser() method on an existing Cell to obtain a reader that supports loading specific types.
### Creating a `Cell` and writing data to it:
```rust
use anyhow::anyhow;
use tonlib_core::TonAddress;
use tonlib_core::cell::CellBuilder;
fn write_cell() -> anyhow::Result<()> {
let mut writer = CellBuilder::new();
let addr = TonAddress::from_base64_url("EQDk2VTvn04SUKJrW7rXahzdF8_Qi6utb0wj43InCu9vdjrR")?;
let cell = writer
.store_u32(32, 0xFAD45AADu32)?
.store_bit(true)?
.store_u8(8, 234u8)?
.store_slice(&[0xFA, 0xD4, 0x5A, 0xAD, 0xAA, 0x12, 0xFF, 0x45])?
.store_address(&addr)?
.store_string("Hello, TON")?
.build()?;
# Ok(())
}
Reading data from a Cell:
use tonlib_core::cell::Cell;
fn read_cell(cell: Cell) -> anyhow::Result<()> {
let mut reader = cell.parser();
let u32_value = reader.load_u32(32)?;
let bit_value = reader.load_bit()?;
let u8_value = reader.load_u8(8)?;
let bytes_value = reader.load_bytes(8)?;
let address_value = reader.load_address()?;
let str_value = reader.ensure_empty()?;
Ok(())
}