Skip to content

Commit

Permalink
optimal-compute-core: make fields on Val and Arg public
Browse files Browse the repository at this point in the history
- `Val::into_inner` is no longer necessary,
  so it was removed.
  • Loading branch information
justinlovinger committed Sep 12, 2024
1 parent ef729bc commit 03e1fa9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
29 changes: 19 additions & 10 deletions optimal-compute-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,20 @@ pub trait ComputationFn: Computation {
}

#[derive(Clone, Copy, Debug)]
pub struct Val<Dim, A> {
pub struct Val<Dim, A>
where
Self: Computation,
{
dim: PhantomData<Dim>,
inner: A,
pub inner: A,
}

#[derive(Clone, Copy, Debug)]
pub struct Arg<Dim, A> {
name: &'static str,
pub struct Arg<Dim, A>
where
Self: Computation,
{
pub name: &'static str,
dim: PhantomData<Dim>,
elem: PhantomData<A>,
}
Expand All @@ -389,17 +395,16 @@ pub type Arg0<A> = Arg<Zero, A>;
pub type Arg1<A> = Arg<One, A>;
pub type Arg2<A> = Arg<Two, A>;

impl<Dim, A> Val<Dim, A> {
impl<Dim, A> Val<Dim, A>
where
Self: Computation,
{
pub fn new(value: A) -> Self {
Val {
dim: PhantomData,
inner: value,
}
}

pub fn into_inner(self) -> A {
self.inner
}
}

impl<Dim, A> Arg<Dim, A> {
Expand Down Expand Up @@ -510,14 +515,18 @@ where

impl<D, A> fmt::Display for Val<Suc<D>, A>
where
Self: Computation,
A: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.inner)
}
}

impl<Dim, A> fmt::Display for Arg<Dim, A> {
impl<Dim, A> fmt::Display for Arg<Dim, A>
where
Self: Computation,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.name)
}
Expand Down
6 changes: 5 additions & 1 deletion optimal-compute-core/src/run/run_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ pub trait RunCore {
fn run_core(self, args: ArgVals) -> Self::Output;
}

impl<Dim, A> RunCore for Val<Dim, A> {
impl<Dim, A> RunCore for Val<Dim, A>
where
Self: Computation,
{
type Output = Value<A>;

fn run_core(self, _args: ArgVals) -> Self::Output {
Expand All @@ -39,6 +42,7 @@ impl<Dim, A> RunCore for Val<Dim, A> {

impl<A> RunCore for Arg<Zero, A>
where
Self: Computation,
A: 'static + ArgVal,
{
type Output = Value<A>;
Expand Down

0 comments on commit 03e1fa9

Please sign in to comment.