Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
senesens
senesens
@senesens@tilde.zone  路  activity timestamp 2 days ago

#rust

ladies and gents, the rare self-referential rust type. Did not know Self syntax was supported on the type declaration.

The following snippet of rust code with colored syntax: 
```
#[derive(Debug, Serialize, Deserialize, Validate, Clone)]
#[serde(rename_all = "camelCase")]
pub enum DocPredicateClause {
    HasTag(#[garde(dive)] PropTag),
    Or(#[garde(dive)] Vec<Self>),
    And(#[garde(dive)] Vec<Self>),
    Not(#[garde(dive)] Box<Self>),
}
```
The following snippet of rust code with colored syntax: ``` #[derive(Debug, Serialize, Deserialize, Validate, Clone)] #[serde(rename_all = "camelCase")] pub enum DocPredicateClause { HasTag(#[garde(dive)] PropTag), Or(#[garde(dive)] Vec<Self>), And(#[garde(dive)] Vec<Self>), Not(#[garde(dive)] Box<Self>), } ```
The following snippet of rust code with colored syntax: ``` #[derive(Debug, Serialize, Deserialize, Validate, Clone)] #[serde(rename_all = "camelCase")] pub enum DocPredicateClause { HasTag(#[garde(dive)] PropTag), Or(#[garde(dive)] Vec<Self>), And(#[garde(dive)] Vec<Self>), Not(#[garde(dive)] Box<Self>), } ```
1
  • Copy link
  • Flag this post
  • Block
kpcyrd 馃彺
kpcyrd 馃彺
@kpcyrd@chaos.social replied  路  activity timestamp 2 days ago

@senesens In both Vec and Box it's fine because both are pointers to the heap. Without them, the compiler would attempt to inline the struct into itself (which wouldn't work), but through this indirection it's okay. The Vec also allows the list to be empty, otherwise you wouldn't be able to create an object without already having an object (causing a chicken-egg problem).

  • Copy link
  • Flag this comment
  • Block

Kakapo Social

Kakapo Social: About 路 Code of conduct 路 Privacy 路 Users 路 Instances
Bonfire social 路 1.0.1-beta.22 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct