From 0c69ee37f98ce616df5237cbe74952c2a28cc5cb Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 22 Jun 2024 12:05:11 -0700 Subject: VecSink only needs `alloc`, hide struct items --- src/annotation/mod.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src/annotation') diff --git a/src/annotation/mod.rs b/src/annotation/mod.rs index 0d1f1f8..9edf262 100644 --- a/src/annotation/mod.rs +++ b/src/annotation/mod.rs @@ -94,24 +94,34 @@ impl DescriptionSink for NullSink { fn record(&mut self, _start: u32, _end: u32, _description: T) { } } -#[cfg(feature = "std")] -pub struct VecSink { - pub records: std::vec::Vec<(u32, u32, T)> -} +#[cfg(feature = "alloc")] +mod vec_sink { + use alloc::vec::Vec; + use core::fmt::Display; + use crate::annotation::DescriptionSink; -#[cfg(feature = "std")] -impl VecSink { - pub fn new() -> Self { - VecSink { records: std::vec::Vec::new() } + pub struct VecSink { + pub records: Vec<(u32, u32, T)> + } + + impl VecSink { + pub fn new() -> Self { + VecSink { records: Vec::new() } + } + + pub fn into_inner(self) -> Vec<(u32, u32, T)> { + self.records + } } -} -#[cfg(feature = "std")] -impl DescriptionSink for VecSink { - fn record(&mut self, start: u32, end: u32, description: T) { - self.records.push((start, end, description)); + impl DescriptionSink for VecSink { + fn record(&mut self, start: u32, end: u32, description: T) { + self.records.push((start, end, description)); + } } } +#[cfg(feature = "alloc")] +pub use vec_sink::VecSink; pub trait FieldDescription { fn id(&self) -> u32; -- cgit v1.1