pub struct Singleton {
pub name: Identifier,
pub generics: Vec<GenericParam>,
pub parents: Vec<Parent>,
pub items: Vec<Item>,
pub annotations: Vec<Attribute>,
pub span: Span,
}Expand description
A singleton declaration.
Singletons are classes that have exactly one instance globally. They are useful for managing global state, configuration, or resources.
§Example
singleton GlobalConfig {
host: String = "localhost"
port: i32 = 8080
micro get_url(self) -> String {
f"{self.host}:{self.port}"
}
}§Semantics
- A singleton has exactly one global instance
- The instance is lazily initialized on first access
- Singleton members are accessed through the singleton name directly
- Singletons cannot be instantiated with constructors
Fields§
§name: IdentifierThe singleton name.
generics: Vec<GenericParam>Generic parameters for the singleton.
parents: Vec<Parent>Parent traits this singleton implements.
items: Vec<Item>Items (fields, methods) declared within the singleton.
annotations: Vec<Attribute>Annotations applied to the singleton.
span: SpanThe source code span.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Singleton
impl<'de> Deserialize<'de> for Singleton
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
impl Eq for Singleton
impl StructuralPartialEq for Singleton
Auto Trait Implementations§
impl Freeze for Singleton
impl RefUnwindSafe for Singleton
impl Send for Singleton
impl Sync for Singleton
impl Unpin for Singleton
impl UnsafeUnpin for Singleton
impl UnwindSafe for Singleton
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