/
githubmirror
/
sway
Обзор
Документация
Войти
/
githubmirror
/
sway
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/methods_and_associated_functions/src/main.sw
28 строк
606 B
Igor Rončević
Struct field privacy (#5508)
30 янв 2024, 16:15
Не верифицирован
30 янв 2024, 16:15
8320c1b
Код
Авторство
О чём код?
script; struct Foo { bar: u64, baz: bool, } impl Foo { // this is a _method_, as it takes `self` as a parameter. fn is_baz_true(self) -> bool { self.baz } // this is an _associated function_, since it does not take `self` as a parameter. // it is at the same time a _constructor_ because it instantiates and returns // a new instance of `Foo`. fn new_foo(number: u64, boolean: bool) -> Foo { Foo { bar: number, baz: boolean, } } } fn main() { let foo = Foo::new_foo(42, true); assert(foo.is_baz_true()); }