use crate::{
ast::AstQPath,
common::{SpanId, SymbolId},
context::with_cx,
ffi::FfiSlice,
};
use super::{CommonPatData, PatKind};
#[repr(C)]
#[derive(Debug)]
pub struct StructPat<'ast> {
data: CommonPatData<'ast>,
path: AstQPath<'ast>,
fields: FfiSlice<'ast, StructFieldPat<'ast>>,
is_non_exhaustive: bool,
}
impl<'ast> StructPat<'ast> {
pub fn path(&self) -> &AstQPath<'ast> {
&self.path
}
pub fn fields(&self) -> &[StructFieldPat<'ast>] {
self.fields.get()
}
pub fn is_non_exhaustive(&self) -> bool {
self.is_non_exhaustive
}
}
super::impl_pat_data!(StructPat<'ast>, Struct);
#[cfg(feature = "driver-api")]
impl<'ast> StructPat<'ast> {
pub fn new(
data: CommonPatData<'ast>,
path: AstQPath<'ast>,
fields: &'ast [StructFieldPat<'ast>],
is_non_exhaustive: bool,
) -> Self {
Self {
data,
path,
fields: fields.into(),
is_non_exhaustive,
}
}
}
#[repr(C)]
#[derive(Debug)]
pub struct StructFieldPat<'ast> {
span: SpanId,
ident: SymbolId,
pat: PatKind<'ast>,
}
impl<'ast> StructFieldPat<'ast> {
pub fn ident(&self) -> &str {
with_cx(self, |cx| cx.symbol_str(self.ident))
}
pub fn pat(&self) -> PatKind<'ast> {
self.pat
}
}
crate::span::impl_has_span_via_field!(StructFieldPat<'ast>);
#[cfg(feature = "driver-api")]
impl<'ast> StructFieldPat<'ast> {
pub fn new(span: SpanId, ident: SymbolId, pat: PatKind<'ast>) -> Self {
Self { span, ident, pat }
}
}