use openusd::Result;
use openusd::sdf;
use openusd::usd::SchemaBase;
use super::connectable::{authored_inputs, input_name, output_name};
use super::{Input, Output};
pub trait Connectable: SchemaBase {
fn input(&self, base: &str) -> Input {
Input::new(self.prim().attribute(input_name(base)))
}
fn create_input(&self, base: &str, type_name: impl Into<sdf::ValueTypeName>) -> Result<Input> {
Ok(Input::new(
self.prim()
.create_attribute(input_name(base), type_name)?
.set_custom(false)?,
))
}
fn inputs(&self) -> Result<Vec<Input>> {
authored_inputs(self.prim())
}
fn output(&self, base: &str) -> Output {
Output::new(self.prim().attribute(output_name(base)))
}
fn create_output(&self, base: &str, type_name: impl Into<sdf::ValueTypeName>) -> Result<Output> {
Ok(Output::new(
self.prim()
.create_attribute(output_name(base), type_name)?
.set_custom(false)?,
))
}
fn outputs(&self) -> Result<Vec<Output>> {
Ok(self
.prim()
.authored_attributes()?
.into_iter()
.filter_map(Output::from_attribute)
.collect())
}
}