Struct and its Abilities
struct NAME has Abilities
{
FIELD1 : TYPE1,
FIELD2 : TYPE2,
...
}module my_addrx::Application {
use std::vector;
use std::debug;
use std::string::{String,utf8};
struct Users has key,drop {
list_of_users: vector<User> //storing the list of the users
}
struct User has store,drop,copy {
name:String, //information required for a typical user
age:u8
}
//creating a user by adding the user to the existing list and returning the user
public fun create_user(newUser: User,users: &mut Users): User{
vector::push_back(&mut users.list_of_users,newUser);
return newUser
}
#[test]
fun test_create_friend(){
let user1 = User {
name:utf8(b"Tony"),
age:50,
};
let users = Users{
list_of_users: vector::empty<User>()
};
let createdUser = create_user(user1,&mut users);
debug::print(&users);
assert!(createdUser.name == utf8(b"Tony"),0);
}
}Last updated