Skip to content

Commit 8435d5a

Browse files
authored
feat(tket2-hseries): make result operation internals public (#542)
1 parent a76a147 commit 8435d5a

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tket2-hseries/src/extension/result.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ pub enum ResultOpDef {
100100
}
101101

102102
impl ResultOpDef {
103-
fn arg_type(&self) -> Type {
103+
/// Type of the argument to the result operation.
104+
pub fn arg_type(&self) -> Type {
104105
match self {
105106
Self::Bool => BOOL_T,
106107
Self::Int | Self::UInt => int_tv(1),
@@ -133,7 +134,8 @@ impl ResultOpDef {
133134
}
134135
}
135136

136-
fn type_params(&self) -> Vec<TypeParam> {
137+
/// Type parameters for result operation.
138+
pub fn type_params(&self) -> Vec<TypeParam> {
137139
match self {
138140
Self::Bool | Self::F64 => vec![],
139141
Self::Int | Self::UInt => vec![LOG_WIDTH_TYPE_PARAM],
@@ -145,7 +147,8 @@ impl ResultOpDef {
145147
}
146148
}
147149

148-
fn instantiate(&self, args: &[TypeArg]) -> Result<ResultOp, OpLoadError> {
150+
/// Instantiate the result operation with the given type arguments.
151+
pub fn instantiate(&self, args: &[TypeArg]) -> Result<ResultOp, OpLoadError> {
149152
let parsed_args = concrete_result_op_type_args(args)?;
150153

151154
match (parsed_args, self) {
@@ -214,23 +217,32 @@ impl MakeOpDef for ResultOpDef {
214217
}
215218

216219
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)]
217-
enum SimpleArgs {
220+
/// Type arguments to a numeric result operation (not an array).
221+
pub enum SimpleArgs {
222+
/// No type arguments, simple result type.
218223
Basic,
224+
/// Integer type argument, specifying bit width.
219225
Int(u8),
220226
}
221227

222228
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)]
223-
enum ResultArgs {
229+
/// Arguments to a "tket2.result" operation.
230+
pub enum ResultArgs {
231+
/// Simple result type, not an array.
224232
Simple(SimpleArgs),
233+
/// Argument for array result type, with inner type arguments and array size.
225234
Array(SimpleArgs, u64),
226235
}
227236

228237
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq)]
229238
/// Concrete instantiation of a "tket2.result" operation.
230239
pub struct ResultOp {
231-
tag: String,
232-
result_op: ResultOpDef,
233-
args: ResultArgs,
240+
/// Static string tag for the result.
241+
pub tag: String,
242+
/// The result operation definition.
243+
pub result_op: ResultOpDef,
244+
/// Type arguments for the result operation.
245+
pub args: ResultArgs,
234246
}
235247

236248
impl ResultOp {

0 commit comments

Comments
 (0)