use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PortKind {
Features,
Raster,
Sprite,
Brush,
Scalar,
ScalarField,
}
impl fmt::Display for PortKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
PortKind::Features => "features",
PortKind::Raster => "raster",
PortKind::Sprite => "sprite",
PortKind::Brush => "brush",
PortKind::Scalar => "scalar",
PortKind::ScalarField => "scalar-field",
})
}
}
#[derive(Debug, Clone)]
pub struct PortSpec {
pub name: &'static str,
pub accepts: &'static [PortKind],
pub optional: bool,
}
impl PortSpec {
pub const fn new(name: &'static str, accepts: &'static [PortKind]) -> Self {
Self {
name,
accepts,
optional: false,
}
}
pub const fn any_of(name: &'static str, accepts: &'static [PortKind]) -> Self {
Self {
name,
accepts,
optional: false,
}
}
pub const fn optional(mut self) -> Self {
self.optional = true;
self
}
pub fn accepts_kind(&self, kind: PortKind) -> bool {
self.accepts.contains(&kind)
}
pub fn primary_kind(&self) -> PortKind {
self.accepts[0]
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CoordSpace {
Tile,
World,
Inherit,
}