Skip to content

Instantly share code, notes, and snippets.

use box::BoxTrait;
#[derive(Drop)]
struct MyStruct {
a: Box<InnerStruct>,
b: felt252,
c: felt252
}
#[derive(Copy, Drop)]
struct InnerStruct {
@tdelabro
tdelabro / no_std-guide.md
Last active April 5, 2024 22:19
How to easely port a crate to `no_std`?

What is Rust's standard library?

One of the Rust programming language promises is "zero-cost abstraction". Therefore the language itself is pretty conservative about what it incorporates. Types that are basics in other languages, such as string, or features, such as async, cannot be part of the language itself because they are costly abstractions. The user may not need them at all, or he may prefer other alternative implementations. To make those types and functions available nonetheless, they are available as part of the Rust standard library, known as std. Part of this library, known as the prelude is imported by default in each .rs file so you don't have to repeat yourself too much.

Why would you want a no_std version of your crate?

Most of the time having this standard library available is not a problem because you run your code on a pretty standard environment: your own computer or a Linux server somewhere in the cloud. However, somet

%builtins output
from starkware.cairo.common.serialize import serialize_word
from starkware.cairo.common.alloc import alloc
func print_words{output_ptr : felt*}(res_len : felt, res : felt*):
if res_len == 0:
return ()
end