use std::borrow::Cow;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct KernelSource {
name: &'static str,
body: KernelSourceBody,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum KernelSourceBody {
Single(&'static str),
Parts(&'static [&'static str]),
}
impl KernelSource {
#[must_use]
pub const fn inline(source: &'static str) -> Self {
Self {
name: "inline.cu",
body: KernelSourceBody::Single(source),
}
}
#[must_use]
pub const fn embedded(name: &'static str, source: &'static str) -> Self {
Self {
name,
body: KernelSourceBody::Single(source),
}
}
#[must_use]
pub const fn composed(name: &'static str, parts: &'static [&'static str]) -> Self {
Self {
name,
body: KernelSourceBody::Parts(parts),
}
}
#[must_use]
pub const fn name(self) -> &'static str {
self.name
}
#[must_use]
pub fn source(self) -> Cow<'static, str> {
match self.body {
KernelSourceBody::Single(source) => Cow::Borrowed(source),
KernelSourceBody::Parts(parts) => Cow::Owned(parts.concat()),
}
}
}