Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xicosahedron committed Nov 9, 2023
1 parent a94ef41 commit 564d4a2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions crates/dojo-lang/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ impl GeneratedFileAuxData for DojoAuxData {
self
}
fn eq(&self, other: &dyn GeneratedFileAuxData) -> bool {
if let Some(other) = other.as_any().downcast_ref::<Self>() {
self == other
} else {
false
}
if let Some(other) = other.as_any().downcast_ref::<Self>() { self == other } else { false }
}
}

Expand Down
28 changes: 28 additions & 0 deletions crates/dojo-lang/src/plugin_test_data/print
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct Player {

name: felt252,
}

#[cfg(test)]
impl PlayerPrintImpl of debug::PrintTrait<Player> {
fn print(self: Player) {
Expand Down Expand Up @@ -133,6 +134,13 @@ struct Player {

name: felt252,
}

#[derive(Print, Copy, Drop, Serde)]
enum Enemy {
Unknown,
Bot: felt252,
OtherPlayer: ContractAddress,
}
impl PositionCopy of Copy::<Position>;
impl PositionDrop of Drop::<Position>;
impl PositionSerde of Serde::<Position> {
Expand Down Expand Up @@ -175,3 +183,23 @@ impl PlayerSerde of Serde::<Player> {
})
}
}
impl EnemyCopy of Copy::<Enemy>;
impl EnemyDrop of Drop::<Enemy>;
impl EnemySerde of Serde::<Enemy> {
fn serialize(self: @Enemy, ref output: array::Array<felt252>) {
match self {
Enemy::Unknown(x) => { serde::Serde::serialize(@0, ref output); serde::Serde::serialize(x, ref output); },
Enemy::Bot(x) => { serde::Serde::serialize(@1, ref output); serde::Serde::serialize(x, ref output); },
Enemy::OtherPlayer(x) => { serde::Serde::serialize(@2, ref output); serde::Serde::serialize(x, ref output); },
}
}
fn deserialize(ref serialized: array::Span<felt252>) -> Option<Enemy> {
let idx: felt252 = serde::Serde::deserialize(ref serialized)?;
Option::Some(
if idx == 0 { Enemy::Unknown(serde::Serde::deserialize(ref serialized)?) }
else if idx == 1 { Enemy::Bot(serde::Serde::deserialize(ref serialized)?) }
else if idx == 2 { Enemy::OtherPlayer(serde::Serde::deserialize(ref serialized)?) }
else { return Option::None; }
)
}
}
7 changes: 4 additions & 3 deletions crates/dojo-lang/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ pub fn handle_print_struct(db: &dyn SyntaxGroup, struct_ast: ItemStruct) -> Rewr
/// Returns:
/// * A RewriteNode containing the generated code.
pub fn handle_print_enum(db: &dyn SyntaxGroup, enum_ast: ItemEnum) -> RewriteNode {
let enum_name = enum_ast.name(db).text(db);
let prints: Vec<_> = enum_ast
.variants(db)
.elements(db)
.iter()
.map(|m| {
format!(
"{} => {{ debug::PrintTrait::print('{}'); }}",
"{}::{}(value) => {{ debug::PrintTrait::print('{}'); \
debug::PrintTrait::print(value); }}",
enum_name,
m.name(db).text(db).to_string(),
m.name(db).text(db).to_string()
)
})
.collect();

dbg!(&prints);

RewriteNode::interpolate_patched(
"#[cfg(test)]
impl $type_name$EnumPrintImpl of debug::PrintTrait<$type_name$> {
Expand Down

0 comments on commit 564d4a2

Please sign in to comment.