use std::sync::Arc;
use hugr::extension::ExtensionRegistry;
use hugr::types::Signature;
use hugr::{Hugr, HugrView, Node};
use crate::serialize::pytket::{PytketDecoderConfig, PytketEncoderConfig};
use super::default_decoder_config;
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct DecodeOptions {
pub config: Option<Arc<PytketDecoderConfig>>,
pub signature: Option<Signature>,
pub input_params: Vec<String>,
pub extensions: Option<ExtensionRegistry>,
}
impl DecodeOptions {
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_config(mut self, config: impl Into<Arc<PytketDecoderConfig>>) -> Self {
self.config = Some(config.into());
self
}
#[must_use]
pub fn with_default_config(mut self) -> Self {
self.config = Some(Arc::new(default_decoder_config()));
self
}
#[must_use]
pub fn with_signature(mut self, signature: Signature) -> Self {
self.signature = Some(signature);
self
}
#[must_use]
pub fn with_input_params(mut self, input_params: impl IntoIterator<Item = String>) -> Self {
self.input_params = input_params.into_iter().collect();
self
}
#[must_use]
pub fn with_extensions(mut self, extensions: ExtensionRegistry) -> Self {
self.extensions = Some(extensions);
self
}
pub fn extension_registry(&self) -> &ExtensionRegistry {
self.extensions
.as_ref()
.unwrap_or(&crate::extension::REGISTRY)
}
}
#[derive(Debug, derive_more::Display, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DecodeInsertionTarget {
#[display("{}",
match fn_name {
Some(fn_name) => format!("Function({fn_name})"),
None => "Function".to_string(),
}
)]
Function {
fn_name: Option<String>,
},
#[display("Region({parent})")]
Region {
parent: Node,
},
}
impl DecodeInsertionTarget {
pub fn function(fn_name: impl ToString) -> Self {
Self::Function {
fn_name: Some(fn_name.to_string()),
}
}
}
impl Default for DecodeInsertionTarget {
fn default() -> Self {
Self::Function { fn_name: None }
}
}
#[derive(Clone)]
#[non_exhaustive]
pub struct EncodeOptions<H: HugrView = Hugr> {
pub config: Option<Arc<PytketEncoderConfig<H>>>,
pub encode_subcircuits: bool,
}
impl<H: HugrView> EncodeOptions<H> {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(mut self, config: impl Into<Arc<PytketEncoderConfig<H>>>) -> Self {
self.config = Some(config.into());
self
}
pub fn with_subcircuits(mut self, encode_subcircuits: bool) -> Self {
self.encode_subcircuits = encode_subcircuits;
self
}
}
impl<H: HugrView> Default for EncodeOptions<H> {
fn default() -> Self {
Self {
config: Default::default(),
encode_subcircuits: Default::default(),
}
}
}