Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract ArrayValue, ArrayType, MapValue, MapType to own files #387

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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