#[non_exhaustive]pub enum Term {
Show 19 variants
RuntimeType(TypeBound),
StaticType,
BoundedNatType(UpperBound),
StringType,
BytesType,
FloatType,
ListType(Box<Term>),
TupleType(Box<Term>),
Runtime(TypeBase<NoRV>),
BoundedNat(u64),
String(String),
Bytes(Arc<[u8]>),
Float(OrderedFloat<f64>),
List(Vec<Term>),
ListConcat(Vec<Term>),
Tuple(Vec<Term>),
TupleConcat(Vec<Term>),
Variable(TermVar),
ConstType(Box<TypeBase<NoRV>>),
}Expand description
A term in the language of static parameters in HUGR.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
RuntimeType(TypeBound)
The type of runtime types.
StaticType
The type of static data.
BoundedNatType(UpperBound)
The type of static natural numbers up to a given bound.
StringType
The type of static strings. See Term::String.
BytesType
The type of static byte strings. See Term::Bytes.
FloatType
The type of static floating point numbers. See Term::Float.
ListType(Box<Term>)
The type of static lists of indeterminate size containing terms of the specified static type.
TupleType(Box<Term>)
The type of static tuples.
Runtime(TypeBase<NoRV>)
A runtime type as a term. Instance of Term::RuntimeType.
BoundedNat(u64)
A 64bit unsigned integer literal. Instance of Term::BoundedNatType.
String(String)
UTF-8 encoded string literal. Instance of Term::StringType.
Bytes(Arc<[u8]>)
Byte string literal. Instance of Term::BytesType.
Float(OrderedFloat<f64>)
A 64-bit floating point number. Instance of Term::FloatType.
List(Vec<Term>)
A list of static terms. Instance of Term::ListType.
ListConcat(Vec<Term>)
Instance of TypeParam::List defined by a sequence of concatenated lists of the same type.
Tuple(Vec<Term>)
Instance of TypeParam::Tuple defined by a sequence of elements of varying type.
TupleConcat(Vec<Term>)
Instance of TypeParam::Tuple defined by a sequence of concatenated tuples.
Variable(TermVar)
Variable (used in type schemes or inside polymorphic functions), but not a runtime type (not even a row variable i.e. list of runtime types)
ConstType(Box<TypeBase<NoRV>>)
The type of constants for a runtime type.
A constant is a compile time description of how to produce a runtime value. The runtime value is constructed when the constant is loaded.
Constants are distinct from the runtime values that they describe. In particular, as part of the term language, constants can be freely copied or destroyed even when they describe a non-linear runtime value.
Implementations§
Source§impl Term
impl Term
Sourcepub const fn max_nat_type() -> Term
pub const fn max_nat_type() -> Term
Creates a Term::BoundedNatType with the maximum bound (u64::MAX + 1).
Sourcepub const fn bounded_nat_type(upper_bound: NonZero<u64>) -> Term
pub const fn bounded_nat_type(upper_bound: NonZero<u64>) -> Term
Creates a Term::BoundedNatType with the stated upper bound (non-exclusive).
Sourcepub fn new_list(items: impl IntoIterator<Item = Term>) -> Term
pub fn new_list(items: impl IntoIterator<Item = Term>) -> Term
Creates a new Term::List given a sequence of its items.
Sourcepub fn new_list_type(elem: impl Into<Term>) -> Term
pub fn new_list_type(elem: impl Into<Term>) -> Term
Creates a new Term::ListType given the type of its elements.
Sourcepub fn new_tuple_type(item_types: impl Into<Term>) -> Term
pub fn new_tuple_type(item_types: impl Into<Term>) -> Term
Creates a new Term::TupleType given the type of its elements.
Source§impl Term
impl Term
Sourcepub const UNIT: Term
pub const UNIT: Term
Type::UNIT as a Term::Runtime
Sourcepub fn new_var_use(idx: usize, decl: Term) -> Term
pub fn new_var_use(idx: usize, decl: Term) -> Term
Makes a TypeArg representing a use (occurrence) of the type variable
with the specified index.
decl must be exactly that with which the variable was declared.
Sourcepub fn new_string(str: impl ToString) -> Term
pub fn new_string(str: impl ToString) -> Term
Creates a new string literal.
Sourcepub fn new_list_concat(lists: impl IntoIterator<Item = Term>) -> Term
pub fn new_list_concat(lists: impl IntoIterator<Item = Term>) -> Term
Creates a new concatenated list.
Sourcepub fn new_tuple(items: impl IntoIterator<Item = Term>) -> Term
pub fn new_tuple(items: impl IntoIterator<Item = Term>) -> Term
Creates a new tuple from its items.
Sourcepub fn new_tuple_concat(tuples: impl IntoIterator<Item = Term>) -> Term
pub fn new_tuple_concat(tuples: impl IntoIterator<Item = Term>) -> Term
Creates a new concatenated tuple.
Sourcepub fn as_nat(&self) -> Option<u64>
pub fn as_nat(&self) -> Option<u64>
Returns an integer if the Term is a natural number literal.
Sourcepub fn as_runtime(&self) -> Option<TypeBase<NoRV>>
pub fn as_runtime(&self) -> Option<TypeBase<NoRV>>
Sourcepub fn new_list_from_parts(
parts: impl IntoIterator<Item = SeqPart<Term>>,
) -> Term
pub fn new_list_from_parts( parts: impl IntoIterator<Item = SeqPart<Term>>, ) -> Term
Creates a new list from a sequence of SeqParts.
Sourcepub fn into_list_parts(self) -> ListPartIter ⓘ
pub fn into_list_parts(self) -> ListPartIter ⓘ
Iterates over the SeqParts of a list.
§Examples
The parts of a closed list are the items of that list wrapped in SeqPart::Item:
let term = Term::new_list([a.clone(), b.clone()]);
assert_eq!(
term.into_list_parts().collect::<Vec<_>>(),
vec![SeqPart::Item(a), SeqPart::Item(b)]
);Parts of a concatenated list that are not closed lists are wrapped in SeqPart::Splice:
let var = Term::new_var_use(0, Term::new_list_type(Term::StringType));
let term = Term::new_list_concat([
Term::new_list([a.clone(), b.clone()]),
var.clone(),
Term::new_list([c.clone()])
]);
assert_eq!(
term.into_list_parts().collect::<Vec<_>>(),
vec![SeqPart::Item(a), SeqPart::Item(b), SeqPart::Splice(var), SeqPart::Item(c)]
);Nested concatenations are traversed recursively:
let term = Term::new_list_concat([
Term::new_list_concat([
Term::new_list([a.clone()]),
Term::new_list([b.clone()])
]),
Term::new_list([]),
Term::new_list([c.clone()])
]);
assert_eq!(
term.into_list_parts().collect::<Vec<_>>(),
vec![SeqPart::Item(a), SeqPart::Item(b), SeqPart::Item(c)]
);When invoked on a type argument that is not a list, a single
SeqPart::Splice is returned that wraps the type argument.
This is the expected behaviour for type variables that stand for lists.
This behaviour also allows this method not to fail on ill-typed type arguments.
let term = Term::new_string("not a list");
assert_eq!(
term.clone().into_list_parts().collect::<Vec<_>>(),
vec![SeqPart::Splice(term)]
);Sourcepub fn new_tuple_from_parts(
parts: impl IntoIterator<Item = SeqPart<Term>>,
) -> Term
pub fn new_tuple_from_parts( parts: impl IntoIterator<Item = SeqPart<Term>>, ) -> Term
Creates a new tuple from a sequence of SeqParts.
Analogous to TypeArg::new_list_from_parts.
Sourcepub fn into_tuple_parts(self) -> TuplePartIter ⓘ
pub fn into_tuple_parts(self) -> TuplePartIter ⓘ
Iterates over the SeqParts of a tuple.
Analogous to TypeArg::into_list_parts.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Term
impl<'de> Deserialize<'de> for Term
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Term, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Term, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<TypeRowBase<RowVariable>> for Term
impl From<TypeRowBase<RowVariable>> for Term
Source§fn from(value: TypeRowBase<RowVariable>) -> Term
fn from(value: TypeRowBase<RowVariable>) -> Term
Source§impl From<UpperBound> for Term
impl From<UpperBound> for Term
Source§fn from(bound: UpperBound) -> Term
fn from(bound: UpperBound) -> Term
Source§impl Serialize for Term
impl Serialize for Term
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Transformable for Term
impl Transformable for Term
Source§fn transform<T>(&mut self, tr: &T) -> Result<bool, <T as TypeTransformer>::Err>where
T: TypeTransformer,
fn transform<T>(&mut self, tr: &T) -> Result<bool, <T as TypeTransformer>::Err>where
T: TypeTransformer,
TypeTransformer to this instance. Read moreSource§impl TryFrom<Term> for TypeRowBase<RowVariable>
impl TryFrom<Term> for TypeRowBase<RowVariable>
Source§type Error = SignatureError
type Error = SignatureError
Source§fn try_from(
value: Term,
) -> Result<TypeRowBase<RowVariable>, <TypeRowBase<RowVariable> as TryFrom<Term>>::Error>
fn try_from( value: Term, ) -> Result<TypeRowBase<RowVariable>, <TypeRowBase<RowVariable> as TryFrom<Term>>::Error>
impl Eq for Term
impl StructuralPartialEq for Term
Auto Trait Implementations§
impl Freeze for Term
impl !RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl !UnwindSafe for Term
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.