pub struct Contract {
pub name: String,
pub init_params: FieldList,
pub fields: FieldList,
pub transitions: TransitionList,
}Expand description
The Contract struct represents a parsed contract in Rust, including its name, initialization
parameters, fields, and transitions.
Fields§
§name: StringName of the parsed contract
init_params: FieldListList of parameters needed to deploy the contract.
fields: FieldListList of the contract’s fields.
transitions: TransitionListList of the contract’s transitions.
Implementations§
Source§impl Contract
impl Contract
Sourcepub fn parse(contract_path: &Path) -> Result<Self, Error>
pub fn parse(contract_path: &Path) -> Result<Self, Error>
Parse a contract from a given path.
§Examples
use std::{error::Error, path::PathBuf};
use scilla_parser::{Contract, Field, FieldList, Transition, TransitionList, Type};
let contract_path = PathBuf::from("tests/contracts/chainid.scilla");
let contract = Contract::parse(&contract_path).unwrap();
assert_eq!(
contract,
Contract {
name: "ChainId".to_string(),
fields: FieldList(vec![Field::new("dummy_field", Type::Uint256)]),
init_params: FieldList::default(),
transitions: TransitionList(vec![Transition::new(
"EventChainID",
FieldList::default()
)])
}
);Trait Implementations§
Source§impl FromStr for Contract
impl FromStr for Contract
Source§fn from_str(contract: &str) -> Result<Self, Self::Err>
fn from_str(contract: &str) -> Result<Self, Self::Err>
Parse a Contract from a string slice
§Example
use std::{error::Error, path::PathBuf};
use scilla_parser::{Contract, Field, FieldList, Transition, TransitionList, Type};
let contract_path = PathBuf::from("tests/contracts/chainid.scilla");
let contract_str = include_str!("../tests/contracts/chainid.scilla");
let contract = contract_str.parse::<Contract>().unwrap();
assert_eq!(
contract,
Contract {
name: "ChainId".to_string(),
fields: FieldList(vec![Field::new("dummy_field", Type::Uint256)]),
init_params: FieldList::default(),
transitions: TransitionList(vec![Transition::new(
"EventChainID",
FieldList::default()
)])
}
);impl StructuralPartialEq for Contract
Auto Trait Implementations§
impl Freeze for Contract
impl RefUnwindSafe for Contract
impl Send for Contract
impl Sync for Contract
impl Unpin for Contract
impl UnwindSafe for Contract
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more