Skip to content

Commit

Permalink
Extract ArrayValue, ArrayType, MapValue, MapType to own files (
Browse files Browse the repository at this point in the history
…#387)

* move ArrayType to own file

* move MapType to own file

* move ArrayValue to own file

* move MapValue to own file
  • Loading branch information
Centril authored Oct 9, 2023
1 parent 148ea2e commit 0a30c02
Show file tree
Hide file tree
Showing 13 changed files with 517 additions and 493 deletions.
7 changes: 6 additions & 1 deletion crates/sats/src/algebraic_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ pub mod ser;
use std::collections::BTreeMap;
use std::ops::{Bound, RangeBounds};

use crate::builtin_value::{F32, F64};
use crate::{AlgebraicType, ArrayValue, BuiltinType, BuiltinValue, ProductValue, SumValue};
use enum_as_inner::EnumAsInner;

/// Totally ordered [`f32`] allowing all IEEE-754 floating point values.
pub type F32 = decorum::Total<f32>;

/// Totally ordered [`f64`] allowing all IEEE-754 floating point values.
pub type F64 = decorum::Total<f64>;

/// A value in SATS typed at some [`AlgebraicType`].
///
/// Values are type erased, so they do not store their type.
Expand Down
2 changes: 1 addition & 1 deletion crates/sats/src/algebraic_value/de.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::builtin_value::{ArrayValueIntoIter, ArrayValueIterCloned};
use crate::array_value::{ArrayValueIntoIter, ArrayValueIterCloned};
use crate::{de, AlgebraicValue, SumValue};

use derive_more::From;
Expand Down
24 changes: 24 additions & 0 deletions crates/sats/src/array_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::algebraic_type::AlgebraicType;
use crate::de::Deserialize;
use crate::meta_type::MetaType;
use crate::{impl_deserialize, impl_serialize};

/// An array type is a homegeneous product type of dynamic length.
///
/// That is, it is a product type
/// where every element / factor / field is of the same type
/// and where the length is statically unknown.
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct ArrayType {
/// The base type every element of the array has.
pub elem_ty: Box<AlgebraicType>,
}

impl_serialize!([] ArrayType, (self, ser) => self.elem_ty.serialize(ser));
impl_deserialize!([] ArrayType, de => Deserialize::deserialize(de).map(|elem_ty| Self { elem_ty }));

impl MetaType for ArrayType {
fn meta_type() -> AlgebraicType {
AlgebraicType::ZERO_REF
}
}
Loading

0 comments on commit 0a30c02

Please sign in to comment.