Skip to content

Commit

Permalink
mapping & nit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-schott committed Nov 30, 2023
1 parent 313a5e4 commit c94c2c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions compiler/ast/src/mapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{Identifier, Node, NodeID, Type};
use leo_span::Span;

use serde::{Deserialize, Serialize};
use snarkvm::prelude::{Mapping as MappingCore, Network};
use std::fmt;

/// A mapping declaration, e.g `mapping balances: address => u128`.
Expand All @@ -36,6 +37,17 @@ pub struct Mapping {
pub id: NodeID,
}

impl<N: Network> From<&MappingCore<N>> for Mapping {
fn from(mapping: &MappingCore<N>) -> Self {
Self {
identifier: Identifier::from(mapping.name()),
key_type: Type::from(mapping.key().plaintext_type()),
value_type: Type::from(mapping.value().plaintext_type()),
span: Default::default(),
id: Default::default(),
}
}
}
impl fmt::Display for Mapping {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "mapping {}: {} => {}", self.identifier, self.key_type, self.value_type)
Expand Down
2 changes: 1 addition & 1 deletion compiler/ast/src/struct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<N: Network> From<&RecordType<N>> for Struct {
.entries()
.iter()
.map(|(id, entry)| Member {
mode: Mode::None,
mode: if input.owner().is_public() { Mode::Public } else { Mode::Private },
identifier: Identifier::from(id),
type_: match entry {
Public(t) => Type::from(t),
Expand Down

0 comments on commit c94c2c3

Please sign in to comment.