#[non_exhaustive]pub struct ModuleDef { /* private fields */ }Expand description
A validated, canonicalized, immutable module definition.
Cannot be created directly. Instead, create/deserialize a spacetimedb_lib::RawModuleDef and call ModuleDef::try_from.
use spacetimedb_lib::RawModuleDef;
use spacetimedb_schema::def::{ModuleDef, TableDef, IndexDef, TypeDef, ModuleDefLookup, ScopedTypeName};
use spacetimedb_schema::identifier::Identifier;
fn read_raw_module_def_from_file() -> RawModuleDef {
// ...
}
let raw_module_def = read_raw_module_def_from_file();
let module_def = ModuleDef::try_from(raw_module_def).expect("valid module def");
let table_name = Identifier::new("my_table".into()).expect("valid identifier");
let index_name = Identifier::new("my_index".into()).expect("valid identifier");
let scoped_type_name = ScopedTypeName::try_new([], "MyType").expect("valid scoped type name");
let table: Option<&TableDef> = module_def.lookup(&table_name);
let index: Option<&IndexDef> = module_def.lookup(&index_name);
let type_def: Option<&TypeDef> = module_def.lookup(&scoped_type_name);
// etc.Implementations§
Source§impl ModuleDef
impl ModuleDef
Sourcepub fn constraints(&self) -> impl Iterator<Item = &ConstraintDef>
pub fn constraints(&self) -> impl Iterator<Item = &ConstraintDef>
The constraints of the module definition.
Sourcepub fn sequences(&self) -> impl Iterator<Item = &SequenceDef>
pub fn sequences(&self) -> impl Iterator<Item = &SequenceDef>
The sequences of the module definition.
Sourcepub fn schedules(&self) -> impl Iterator<Item = &ScheduleDef>
pub fn schedules(&self) -> impl Iterator<Item = &ScheduleDef>
The schedules of the module definition.
Sourcepub fn reducers(&self) -> impl Iterator<Item = &ReducerDef>
pub fn reducers(&self) -> impl Iterator<Item = &ReducerDef>
The reducers of the module definition.
Sourcepub fn types(&self) -> impl Iterator<Item = &TypeDef>
pub fn types(&self) -> impl Iterator<Item = &TypeDef>
The type definitions of the module definition.
Sourcepub fn row_level_security(
&self,
) -> impl Iterator<Item = &RawRowLevelSecurityDefV9>
pub fn row_level_security( &self, ) -> impl Iterator<Item = &RawRowLevelSecurityDefV9>
The row-level security policies of the module definition.
Sourcepub fn typespace(&self) -> &Typespace
pub fn typespace(&self) -> &Typespace
The Typespace used by the module.
AlgebraicTypeRefs in the table, reducer, and type alias declarations refer to this typespace.
The typespace must satisfy Typespace::is_valid_for_client_code_generation. That is, all types stored in the typespace must either:
- satisfy
AlgebraicType::is_valid_for_client_type_definition - and/or
AlgebraicType::is_valid_for_client_type_use.
Types satisfying condition 1 correspond to generated classes in client code. (Types satisfying condition 2 are an artifact of the module bindings, and do not affect the semantics of the module definition.)
Types satisfying condition 1 are required to have corresponding RawTypeDefV9 declarations in the module.
Sourcepub fn typespace_for_generate(&self) -> &TypespaceForGenerate
pub fn typespace_for_generate(&self) -> &TypespaceForGenerate
The typespace of the module from a different perspective, one useful for client code generation.
Sourcepub fn stored_in_table_def(&self, name: &Identifier) -> Option<&TableDef>
pub fn stored_in_table_def(&self, name: &Identifier) -> Option<&TableDef>
The TableDef an entity in the global namespace is stored in, if any.
Generally, you will want to use the lookup method on the entity type instead.
Sourcepub fn lookup<T: ModuleDefLookup>(&self, key: T::Key<'_>) -> Option<&T>
pub fn lookup<T: ModuleDefLookup>(&self, key: T::Key<'_>) -> Option<&T>
Lookup a definition by its key in self.
Sourcepub fn lookup_expect<T: ModuleDefLookup>(&self, key: T::Key<'_>) -> &T
pub fn lookup_expect<T: ModuleDefLookup>(&self, key: T::Key<'_>) -> &T
Lookup a definition by its key in self, panicking if not found.
Only use this method if you are sure the key exists in the module definition.
Sourcepub fn table<K: ?Sized + Hash + Equivalent<Identifier>>(
&self,
name: &K,
) -> Option<&TableDef>
pub fn table<K: ?Sized + Hash + Equivalent<Identifier>>( &self, name: &K, ) -> Option<&TableDef>
Convenience method to look up a table, possibly by a string.
Sourcepub fn reducer<K: ?Sized + Hash + Equivalent<Identifier>>(
&self,
name: &K,
) -> Option<&ReducerDef>
pub fn reducer<K: ?Sized + Hash + Equivalent<Identifier>>( &self, name: &K, ) -> Option<&ReducerDef>
Convenience method to look up a reducer, possibly by a string.
Sourcepub fn reducer_arg_deserialize_seed<K: ?Sized + Hash + Equivalent<Identifier>>(
&self,
name: &K,
) -> Option<ReducerArgsDeserializeSeed<'_>>
pub fn reducer_arg_deserialize_seed<K: ?Sized + Hash + Equivalent<Identifier>>( &self, name: &K, ) -> Option<ReducerArgsDeserializeSeed<'_>>
Get a DeserializeSeed that can pull data from a Deserializer and format it into a ProductType
at the parameter type of the reducer named name.
Sourcepub fn type_def_from_ref(
&self,
r: AlgebraicTypeRef,
) -> Option<(&ScopedTypeName, &TypeDef)>
pub fn type_def_from_ref( &self, r: AlgebraicTypeRef, ) -> Option<(&ScopedTypeName, &TypeDef)>
Look up the name corresponding to an AlgebraicTypeRef.
Sourcepub fn table_schema<K: ?Sized + Hash + Equivalent<Identifier>>(
&self,
name: &K,
table_id: TableId,
) -> Option<TableSchema>
pub fn table_schema<K: ?Sized + Hash + Equivalent<Identifier>>( &self, name: &K, table_id: TableId, ) -> Option<TableSchema>
Convenience method to look up a table and convert it to a TableSchema.
All indexes, constraints, etc inside the table will have ID 0!
Sourcepub fn expect_lookup<T: ModuleDefLookup>(&self, key: T::Key<'_>) -> &T
pub fn expect_lookup<T: ModuleDefLookup>(&self, key: T::Key<'_>) -> &T
Lookup a definition by its key in self, panicking if it is not found.
Sourcepub fn expect_contains<Def: ModuleDefLookup>(&self, def: &Def)
pub fn expect_contains<Def: ModuleDefLookup>(&self, def: &Def)
Expect that this module definition contains a definition.
Trait Implementations§
Source§impl From<ModuleDef> for RawModuleDefV9
impl From<ModuleDef> for RawModuleDefV9
Source§impl TryFrom<RawModuleDef> for ModuleDef
impl TryFrom<RawModuleDef> for ModuleDef
Source§type Error = ErrorStream<ValidationError>
type Error = ErrorStream<ValidationError>
Source§impl TryFrom<RawModuleDefV8> for ModuleDef
impl TryFrom<RawModuleDefV8> for ModuleDef
Source§type Error = ErrorStream<ValidationError>
type Error = ErrorStream<ValidationError>
Source§impl TryFrom<RawModuleDefV9> for ModuleDef
impl TryFrom<RawModuleDefV9> for ModuleDef
Source§type Error = ErrorStream<ValidationError>
type Error = ErrorStream<ValidationError>
Auto Trait Implementations§
impl Freeze for ModuleDef
impl RefUnwindSafe for ModuleDef
impl Send for ModuleDef
impl Sync for ModuleDef
impl Unpin for ModuleDef
impl UnwindSafe for ModuleDef
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more