diff options
author | iximeow <me@iximeow.net> | 2024-06-22 12:05:11 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2024-06-22 12:05:11 -0700 |
commit | 0c69ee37f98ce616df5237cbe74952c2a28cc5cb (patch) | |
tree | 03054f2df3ead67cc6ce39e9d43d2ddc09a92ab8 /src/annotation | |
parent | 872adb302b1c51cda7b1e99e128129e230e24ff8 (diff) |
VecSink only needs `alloc`, hide struct items
Diffstat (limited to 'src/annotation')
-rw-r--r-- | src/annotation/mod.rs | 36 |
1 files changed, 23 insertions, 13 deletions
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<T> DescriptionSink<T> for NullSink { fn record(&mut self, _start: u32, _end: u32, _description: T) { } } -#[cfg(feature = "std")] -pub struct VecSink<T: Clone + Display> { - 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<T: Clone + Display> VecSink<T> { - pub fn new() -> Self { - VecSink { records: std::vec::Vec::new() } + pub struct VecSink<T: Clone + Display> { + pub records: Vec<(u32, u32, T)> + } + + impl<T: Clone + Display> VecSink<T> { + pub fn new() -> Self { + VecSink { records: Vec::new() } + } + + pub fn into_inner(self) -> Vec<(u32, u32, T)> { + self.records + } } -} -#[cfg(feature = "std")] -impl<T: Clone + Display> DescriptionSink<T> for VecSink<T> { - fn record(&mut self, start: u32, end: u32, description: T) { - self.records.push((start, end, description)); + impl<T: Clone + Display> DescriptionSink<T> for VecSink<T> { + 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; |