pub struct Module {
pub submodules: Submodules,
pub functions: Functions,
pub imports: Imports,
}
Fields§
§submodules: Submodules
§functions: Functions
§imports: Imports
functions to import from submodules
e.g. importing foo.bar
allows you to use a Jump("bar")
Card
Implementations§
Source§impl Module
impl Module
pub fn get_card_mut<'a>( &'a mut self, idx: &CardIndex, ) -> Result<&'a mut Card, CardFetchError>
pub fn get_card<'a>( &'a self, idx: &CardIndex, ) -> Result<&'a Card, CardFetchError>
Sourcepub fn swap_cards<'a>(
&mut self,
lhs: &'a CardIndex,
rhs: &'a CardIndex,
) -> Result<(), SwapError>
pub fn swap_cards<'a>( &mut self, lhs: &'a CardIndex, rhs: &'a CardIndex, ) -> Result<(), SwapError>
swapping a parent and child is an error
pub fn remove_card(&mut self, idx: &CardIndex) -> Result<Card, CardFetchError>
Sourcepub fn replace_card(
&mut self,
idx: &CardIndex,
child: Card,
) -> Result<Card, CardFetchError>
pub fn replace_card( &mut self, idx: &CardIndex, child: Card, ) -> Result<Card, CardFetchError>
Return the old card
pub fn insert_card( &mut self, idx: &CardIndex, child: Card, ) -> Result<(), CardFetchError>
Sourcepub fn compute_keys_hash(&self) -> u64
pub fn compute_keys_hash(&self) -> u64
Hash the keys in the program.
Keys = functions, submodules, card names.
pub fn lookup_submodule(&self, target: &str) -> Option<&Module>
pub fn lookup_submodule_mut(&mut self, target: &str) -> Option<&mut Module>
pub fn lookup_function(&self, target: &str) -> Option<&Function>
pub fn lookup_function_mut(&mut self, target: &str) -> Option<&mut Function>
Sourcepub fn walk_cards_mut(&mut self, op: impl FnMut(&CardIndex, &mut Card))
pub fn walk_cards_mut(&mut self, op: impl FnMut(&CardIndex, &mut Card))
Visits all cards in the module recursively
use cao_lang::prelude::*;
let mut program = CaoProgram {
imports: Default::default(),
submodules: Default::default(),
functions: [
(
"main".into(),
Function::default().with_card(Card::IfTrue(Box::new([
Card::ScalarInt(42),
Card::call_function("pooh", vec![]),
]))),
),
(
"pooh".into(),
Function::default().with_card(Card::set_global_var("result", Card::ScalarInt(69))),
),
]
.into(),
};
program.walk_cards_mut(|id, card| {
// use id, card
});
pub fn walk_cards(&mut self, op: impl FnMut(&CardIndex, &Card))
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Module
impl<'de> Deserialize<'de> for Module
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Module
impl RefUnwindSafe for Module
impl Send for Module
impl Sync for Module
impl Unpin for Module
impl UnwindSafe for Module
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