Skip to content

Commit

Permalink
feat: Add From impls for TypeArg
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed May 8, 2024
1 parent acca7bf commit d22ba59
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions hugr/src/types/type_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ impl From<UpperBound> for TypeParam {
}
}

impl From<Type> for TypeArg {
fn from(ty: Type) -> Self {
Self::Type { ty }
}
}

/// A statically-known argument value to an operation.
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[non_exhaustive]
Expand Down Expand Up @@ -175,6 +169,36 @@ pub enum TypeArg {
},
}

impl From<Type> for TypeArg {
fn from(ty: Type) -> Self {
Self::Type { ty }
}
}

impl From<u64> for TypeArg {
fn from(n: u64) -> Self {
Self::BoundedNat { n }
}
}

impl From<CustomTypeArg> for TypeArg {
fn from(arg: CustomTypeArg) -> Self {
Self::Opaque { arg }
}
}

impl From<Vec<TypeArg>> for TypeArg {
fn from(elems: Vec<TypeArg>) -> Self {
Self::Sequence { elems }
}
}

impl From<ExtensionSet> for TypeArg {
fn from(es: ExtensionSet) -> Self {
Self::Extensions { es }
}
}

/// Variable in a TypeArg, that is not a [TypeArg::Type] or [TypeArg::Extensions],
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct TypeArgVariable {
Expand Down

0 comments on commit d22ba59

Please sign in to comment.